Simulate keypress in a script

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1968
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria
Contact:

Simulate keypress in a script

Post by richmond62 » Tue Jul 19, 2016 7:03 pm

Just as one can use a script like this

send "mouseUp" to btn "BLAH"

it would also be useful if one could simulate keypresses like this;

send "keyUp"("x") to card id 2004

send "rawKeyUp"(123) to card id 2004

send "arrowKey"("up") to card id 2004

SparkOut
Posts: 1643
Joined: Sun Sep 23, 2007 4:58 pm

Re: Simulate keypress in a script

Post by SparkOut » Tue Jul 19, 2016 10:29 pm

Yes, but you can abstract:

Card script:

Code: Select all

on keyUp pkey
   doKeyUpThing pKey
end keyUp

on doKeyUpThing pKey
  answer "do something with" && pKey
end doKeyUpThing
Then instead of sending the keyUp message to the card, you send the doKeyUpThing with whatever parameter you need.

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

Re: Simulate keypress in a script

Post by dunbarx » Wed Jul 20, 2016 1:24 am

Hi.

Try this in a button:

Code: Select all

on mouseUp
   answer keyUp("k")
end mouseUp

on mouseUp
   send "keyup" && "k" to this card
end mouseUp
And in, say, the card script:

Code: Select all

on keyup tKey
   answer tKey
end keyup

function keyUp tKey
   return tKey
end keyUp
Each works in its own way.

Craig

Post Reply

Return to “Feature Requests”