Messaging of arrow key

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
rbrucep
Posts: 21
Joined: Thu Jul 05, 2012 4:25 pm

Messaging of arrow key

Post by rbrucep » Tue Aug 28, 2012 3:57 pm

I'm having trouble getting the expected behavior of arrowkey.
Goal: interrupt the card advance behavior so I can run it through code in next/previous buttons that decides whether to save user data. Do this while preserving editing feature in text fields

I'm trying to use a front script or stack script
If I put the on arrowkey in a front script, I need to let the text field 'keep' the arrow key. I attempt this using
put the long name of the focusedObject into holder to see if user is in such a field
This works fine, but when I attempt
pass "arrowkey" nothing happens; the text object never gets the message and the arrows fail
I have worked around this using my own code to move the selection point laterally [though not vertically], but its not the way I would like to go.

When I put the arrowKey function in the STACK script, it indeed intercepts the arrowkey message--but it does so before the text field in which the user is typing. That makes partial sense, but I'm not sure why the arrowkey behavior was not handled/allowed in the text field prior.

When I put the arrowkey function on the text field, it does nothing when the field is editable, which seems fair, but means I can't stop the message from reaching the stack script, which will somehow stop it from reaching the FIELD, where it was supposed to have started ;)

tl;dr: Any clever way to intercept arrowkey with regard to its card-advancing function (I would prefer disable rather than kill) while still permitting its direct function in editable text fields?

Thanks
Bruce

Klaus
Posts: 14213
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Messaging of arrow key

Post by Klaus » Tue Aug 28, 2012 4:50 pm

Hi Bruce,

1. welcome to the forum
2. try this in the stackscript, just tested and works :D

Code: Select all

on arrowkey tKey
  if the target begins with "field" then
    pass arrowkey
  else
    ## do your ARROWKEY stuff here
  end if
end arrowkey
No need for a special "arrowkey" script in the field(s).
Can of course be refined to check if the target is not locked etc...


Best

Klaus

rbrucep
Posts: 21
Joined: Thu Jul 05, 2012 4:25 pm

Re: Messaging of arrow key

Post by rbrucep » Thu Aug 30, 2012 7:05 pm

Klaus:
Thanks a million. I'll give it a try. I'd done a number of combinations of using front script, stack, and field, but this looks like a different one.

Sorry to be so slow in getting back; teaching classes ;)
Bruce

rbrucep
Posts: 21
Joined: Thu Jul 05, 2012 4:25 pm

Re: Messaging of arrow key

Post by rbrucep » Fri Aug 31, 2012 12:50 am

Klaus:
I wanted to finish the thought. The code works perfectly. In retrospect, it's possible some of my failure was that I experimented with a front script and may have failed to unhook it.

Thanks for your fast and right-on-the-money suggestion!
Bruce

Klaus
Posts: 14213
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Messaging of arrow key

Post by Klaus » Fri Aug 31, 2012 10:33 am

Hi Bruce,

my pleasure :)


Best

Klaus

Post Reply