Can't Find When Field is Active/has Focus
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 7
- Joined: Tue Mar 09, 2021 6:37 pm
- Location: Massachusetts
Can't Find When Field is Active/has Focus
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.
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.
-
- 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
Hi,
You may use selectedfield to know which is the used field and add a condition to your script
Something like that (no tested)
Best regards
Jean-Marc
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
Jean-Marc
Last edited by jmburnod on Mon May 31, 2021 5:36 pm, edited 1 time in total.
https://alternatic.ch
Re: Can't Find When Field is Active/has Focus
Hi Don,
"the selectedfield" will give you the name of the currenlty active field, if any!
This should do the trick
Best
Klaus
"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
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 9647
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Can't Find When Field is Active/has Focus
And in general, the "focusedObject" does that as well, and gives a more detailed "path".
Craig
Craig
Re: Can't Find When Field is Active/has Focus
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...donbeck@donbeck.org wrote: ↑Mon May 31, 2021 5:17 pmI 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.
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
-
- Posts: 7
- Joined: Tue Mar 09, 2021 6:37 pm
- Location: Massachusetts
Re: Can't Find When Field is Active/has Focus
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.
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.
-
- VIP Livecode Opensource Backer
- Posts: 9647
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Can't Find When Field is Active/has Focus
Happens all the time. Hard enough to keep current on current events, never mind past ones.Now I just read that someone had also suggested focusedObject, but I got there before I saw this suggestion.
Craig