Move mobileControl not to be covered by keyboard

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
Posts: 91
Joined: Tue Sep 03, 2013 1:53 pm

Move mobileControl not to be covered by keyboard

Post by gepponline » Thu Mar 19, 2015 4:59 pm

I'm trying to move my control to avoid the keyboard to cover it so i write this script in the stack but it don't seems to work:

Code: Select all

on keyboardActivated
   if the environment is "mobile" then
      if mobileControlTarget() is "numeroAMob" then 
         put the rect of field "numero_A" into rectNumero_A
         set itemdelimiter to ","
         put rectNumero_A into trectPROVV
         put the item 2 of rectNumero_A into tTOP
         subtract 20 from tTOP
         put the item 4 of rectNumero_A into tBOTTOM
         subtract 20 from tBOTTOM
         put tTop into item 2 of trectPROVV
         put tBOTTOM into item 4 of trectPROVV
         mobileControlSet "numeroAMob", "rect", trectPROVV
      end if
   end if
end keyboardActivated

on keyboardDeactivated
   if the environment is "mobile" then      
         mobileControlSet "numeroAMob", "rect", rectNumero_A
   end if
end keyboardDeactivated
Maybe is themobiletarget() that is wrong...

How can i move the control only when the focus is in it?

Is there a more elegant way to avoid the keyboard to cover? Can i shift up the entire card? so my control don't go over others?

Posts: 35
Joined: Sat Dec 13, 2014 11:16 am

Re: Move mobileControl not to be covered by keyboard

Post by hilton » Tue Mar 24, 2015 11:58 am


This is probably not very elegant but it works on Android.

I add a label "lblKeyboard" to the bottom of the card that extends beyond the physical space of the screen. This allows the screen to scroll.
Then in the field I want to jump up above the keyboard I put the code below

Code: Select all

on openField
   local tObj,tPerc,tPosi,tErr
   if the environment is not "mobile" then
      exit openField
   end if
   put the long name of target into tObj
   if tObj contains "grpList" then
      put  (the top of tObj / the height of this card)*100 into tPerc
      if tPerc > 45 then
         put round(height of this card*.4) into tPosi
            set the vScroll of group "grpList" to tPosi
         catch tErr
            answer tErr with "Ok"
         end try
      end if
   end if
end openField
Finally when the keyboard is deactivated (by tapping the back key or focusing elsewhere) I use this code

Code: Select all

on keyboardDeactivated
   focus on nothing
   set the vScroll of group "grpList" to 0
end keyboardDeactivated
Probably clumsy, but works. Hope you can refine it.

Bye Hilton.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”