Focus command question

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: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Pistris
Posts: 148
Joined: Mon Jul 20, 2015 2:40 am

Focus command question

Post by Pistris » Sat Feb 23, 2019 9:35 pm

Hi guys

am having a problem where i have a card that has a field and everytime
that i call that card the keyboard shows up cause it focuses on the field
i have tried using FOCUS ON NOTHING on several parts of my code but
no luck with it
The only way i found to prevent this from happening is disabling it and
the enabling it if i click on it but its not a clean way to do this as i have to make sure
to disable every field

any suggestions?

thanks

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9285
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Focus command question

Post by richmond62 » Sun Feb 24, 2019 12:00 am

the keyboard shows up
Presumably by this you mean that you are programming for Android or iOS.

The best way to stop focussing in fields is to fiddle around in the properties palette
of the field:
-
Screenshot 2019-02-24 at 0.57.42.png

Pistris
Posts: 148
Joined: Mon Jul 20, 2015 2:40 am

Re: Focus command question

Post by Pistris » Sun Feb 24, 2019 1:04 am

Yes already played with those settings
once the card is loaded it will focus on the field regardless
the only way I can make it not focus on it is by disabling it
but that is not what I want to do

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Focus command question

Post by [-hh] » Sun Feb 24, 2019 2:19 am

For me this works:
If the locktext of a field is true then it doesn't trigger the keyboard.
shiftLock happens

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Focus command question

Post by bogs » Sun Feb 24, 2019 1:28 pm

If that doesn't work for you, perhaps some variation of one of the following from this thread will - transversal for instance is mentioned.
Pistris wrote:
Sat Feb 23, 2019 9:35 pm
The only way i found to prevent this from happening is disabling it and
the enabling it if i click on it but its not a clean way to do this as i have to make sure
to disable every field
I'm not sure why this would not be a clean way to do it, something like (psuedo code) -

Code: Select all

on openCard
  repeat with x=1 to the number of controls of this card
    if word 1 of the name of control x is "field" then set the disabled of control x to "true"
  end repeat  
end openCard

on mouseUp (or whatever handler you need to activate the field)
  set the disabled of the target to "false"
end mouseUp
but then, I do no mobile programming, so maybe it is taboo somehow.
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7214
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Focus command question

Post by jacque » Sun Feb 24, 2019 5:17 pm

It's a universal "feature" on all OSs, the first control with traversalOn will get the focus. If it's a field, it gets the insertion point, if it's a button (which can be focused on Windows) it gets the selection outline. On mobile, any field with focus also triggers the keyboard.

Setting the focus is one of the last things LC does after opencard, so you can't trap the behavior directly from any open* message. But you can send a message in time to deal with it. The culprit is traversalOn, and the general idea is:

Code: Select all

on preOpenCard
  tvsOn false 
  send "tvsOn true" to me in 1 millisecond 
end preOpenCard 

on tvsOn pBool
  set the traversalOn of fld 1 to pBool
end tvsOn
Since LC will focus on the first control with traversalOn, you may have to include more than one field in the tvsOn handler.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Pistris
Posts: 148
Joined: Mon Jul 20, 2015 2:40 am

Re: Focus command question

Post by Pistris » Tue Feb 26, 2019 10:44 pm

@jacque Thank you very much
this worked like a charm

@ Bogs, thank you man that also works, but (at least on my phone) when
i try it, it displays the keyboard for a brief moment
when I try it on the simulator the keyboard does not show.
but thanks for taking the time to answer

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Focus command question

Post by bogs » Tue Feb 26, 2019 11:38 pm

Sharing knowledge makes us all better, but I am glad Jacque answered with the 'why' and not just the 'how' :wink:
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”