Can't Find When Field is Active/has Focus

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
donbeck@donbeck.org
Posts: 7
Joined: Tue Mar 09, 2021 6:37 pm
Location: Massachusetts

Can't Find When Field is Active/has Focus

Post by donbeck@donbeck.org » Mon May 31, 2021 5:17 pm

I use the player to play MP3s. I use the following scrip to use the Space Bar to start and stop the player.

on keyUp theKey
if theKey is space then
send mouseUp to btn id 1053 — this is a manual button to start and stop the player
else
pass keyUp
end if
end keyUp

This works fine, but here is my PROBLEM:

I have a search field on the card. When I type more than one word into the search field, every time I press the space bar, the music starts or stops. I am trying to find a way to see if the search field is active, so that I can disable controlling the player when the space bar is used to put a space between words. If I can find this, I will put an IF-THEN statement in the above script. Any help would be appreciated.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Can't Find When Field is Active/has Focus

Post by jmburnod » Mon May 31, 2021 5:28 pm

Hi,
You may use selectedfield to know which is the used field and add a condition to your script
Something like that (no tested)

Code: Select all

if the selectedfield = the num of fld "Mysearchfield" then
Best regards
Jean-Marc
Last edited by jmburnod on Mon May 31, 2021 5:36 pm, edited 1 time in total.
https://alternatic.ch

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Can't Find When Field is Active/has Focus

Post by Klaus » Mon May 31, 2021 5:29 pm

Hi Don,

"the selectedfield" will give you the name of the currenlty active field, if any!
This should do the trick

Code: Select all

## This in the card script:
on keyUp theKey
   ## Cursor is in this field, so we let the keys PASS:
  if the short name of the selectedfield = "your search field here" then
    pass keyup
  end if
  
  if theKey = space then
     ## Message to send in QUOTES and get used to use meaningfule names for your objects! ;-)
     send "mouseUp" to btn id 1053 — this is a manual button to start and stop the player
  else
   pass keyUp
 end if
end keyUp
Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Can't Find When Field is Active/has Focus

Post by dunbarx » Tue Jun 01, 2021 12:03 am

And in general, the "focusedObject" does that as well, and gives a more detailed "path".

Craig

stam
Posts: 2636
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Can't Find When Field is Active/has Focus

Post by stam » Tue Jun 01, 2021 11:59 pm

donbeck@donbeck.org wrote:
Mon May 31, 2021 5:17 pm
I have a search field on the card. When I type more than one word into the search field, every time I press the space bar, the music starts or stops. I am trying to find a way to see if the search field is active, so that I can disable controlling the player when the space bar is used to put a space between words. If I can find this, I will put an IF-THEN statement in the above script. Any help would be appreciated.
in addition to the selectedField, you could also manage the on openField handler (when you enter the field), on closeField (when you exit the field and the text has changed) and the on exitField (when you exit the field and the text hasn't changed) for when you leave the field...
You could set and reset a script or global variable as a flag to not start/stop the music while the field is active.
If you have multiple fields that should behave this way, just create a behaviour script or button and assign the behaviour to all fields that need it.
Lots of ways to do this ;)

donbeck@donbeck.org
Posts: 7
Joined: Tue Mar 09, 2021 6:37 pm
Location: Massachusetts

Re: Can't Find When Field is Active/has Focus

Post by donbeck@donbeck.org » Sun Jun 06, 2021 6:03 pm

Thank you for all of these answers. When I tried “selectedField, it came close to working right, but some other objects also took focus, so I still had a problem. This however gave me a direction to look further, and I found focusedObject, and that did the trick for me.

Now I just read that someone had also suggested focusedObject, but I got there before I saw this suggestion.

I hadn’t thought of the suggestion to use openField/exitField, but I will check this out to see if it has any advantages for my particular application.

For now, problem is solved with focusedObject, and all the help and suggestions that got me there are appreciated.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Can't Find When Field is Active/has Focus

Post by dunbarx » Sun Jun 06, 2021 10:11 pm

Now I just read that someone had also suggested focusedObject, but I got there before I saw this suggestion.
Happens all the time. Hard enough to keep current on current events, never mind past ones.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”