Page 1 of 1
Can't Find When Field is Active/has Focus
Posted: Mon May 31, 2021 5:17 pm
by donbeck@donbeck.org
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.
Re: Can't Find When Field is Active/has Focus
Posted: Mon May 31, 2021 5:28 pm
by jmburnod
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
Re: Can't Find When Field is Active/has Focus
Posted: Mon May 31, 2021 5:29 pm
by Klaus
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
Re: Can't Find When Field is Active/has Focus
Posted: Tue Jun 01, 2021 12:03 am
by dunbarx
And in general, the "focusedObject" does that as well, and gives a more detailed "path".
Craig
Re: Can't Find When Field is Active/has Focus
Posted: Tue Jun 01, 2021 11:59 pm
by stam
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

Re: Can't Find When Field is Active/has Focus
Posted: Sun Jun 06, 2021 6:03 pm
by donbeck@donbeck.org
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.
Re: Can't Find When Field is Active/has Focus
Posted: Sun Jun 06, 2021 10:11 pm
by dunbarx
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