Triggering KeyPresses from buttons

Moderators: LCNeil, heatherlaine, kevinmiller, elanorb

Post Reply
LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Triggering KeyPresses from buttons

Post by LCNeil » Thu Mar 06, 2014 11:39 am

Hi Everyone,

This question came up in this weeks webinar.

Attached is a sample stack that shows how to trigger keypresses from buttons within a LiveCode stack. The rawKeyDown message is being used and this uses the rawkey code of a particular key.
rawkey.livecode.zip
(1.2 KiB) Downloaded 215 times
Kind Regards,


Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
——

DavJans
Posts: 270
Joined: Thu Dec 12, 2013 4:21 pm
Location: Spokane, WA USA

Re: Triggering KeyPresses from buttons

Post by DavJans » Thu Mar 06, 2014 5:45 pm

Thank you Neil
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

DavJans
Posts: 270
Joined: Thu Dec 12, 2013 4:21 pm
Location: Spokane, WA USA

Re: Triggering KeyPresses from buttons

Post by DavJans » Wed Mar 19, 2014 6:45 pm

Late reply here and I'm sorry for that.

I still cant get this to do what I want. If I create a new button in this stack and put this into the code

Code: Select all

on mouseUp
   rawKeyDown "53"
end mouseUp
it gives me an error
"button "Button": execution error at line 2 (Handler: can't find handler) near "rawKeyDown", char 1"
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: Triggering KeyPresses from buttons

Post by LCNeil » Thu Mar 20, 2014 11:36 am

Hi DavJans,

You will still need to handle the rawKeyDown message elsewhere in your stack.

I believe "53" is equal to the "5" key so if you wanted to place 5 into a focused field via a button it would be something like the following-

(on card script)

on rawKeyDown pKey
if pKey is "53" then
put the "5" into the focusedObject
pass rawKeyDown
end if
end rawKeyDown

Kind Regards,


Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
——

DavJans
Posts: 270
Joined: Thu Dec 12, 2013 4:21 pm
Location: Spokane, WA USA

Re: Triggering KeyPresses from buttons

Post by DavJans » Thu Mar 20, 2014 4:24 pm

Thats what im beginning to see, witch leads me back arround to my original problem that is the Return key.

on rawKeyDown pKey
if pKey is "65293" then
--do the return thing either go to the next field if tab on return is on or move down a line if its not...

I'm beginning to think maybe I cant trick it into thinking a button is a real keyboard

I may have to do something like this

on rawKeyDown pKey
if pKey is "65293" then
send closeField to the focusedObject

and then specify in closeField of the object to select the next one i want
but that still don't help me if I just want it to make that next line in a field.

Thank you for your help.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

elanorb
Livecode Staff Member
Livecode Staff Member
Posts: 516
Joined: Fri Feb 24, 2006 9:45 am

Re: Triggering KeyPresses from buttons

Post by elanorb » Thu Mar 20, 2014 6:47 pm

Hi DavJans

You might have explained this in the webinar, and I missed it, but if you can explain to us exactly what you are trying to achieve we might be able to come up with a better way of implementing it.

Sending rawKeyDown messages from a button doesn't seem like the best way to implement something, if you have created a keyboard using buttons, for example, you might be better just implementing them yourself.

For example the code for the "a" button might be

on mouseUp
put "a" after field "input"
end mouseUp

The code for a return button might be

on mouseUp
put return after field "input"
end mouseUp

I realise I might be misunderstanding what you are trying to achieve but it seems like there might be a simpler way.

Kind regards

Elanor
Elanor Buchanan
Software Developer
LiveCode

DavJans
Posts: 270
Joined: Thu Dec 12, 2013 4:21 pm
Location: Spokane, WA USA

Re: Triggering KeyPresses from buttons

Post by DavJans » Thu Mar 20, 2014 7:24 pm

Thank you Elanor,

I tried that and it half way works like I want :)
only thing that doesn't work is this button doesn't care if tab on return is turned on, it ignores it.

this works a little better than your suggestion even as it doesn't limit me to one field.

on mouseUp
put return into the selection
end mouseUp
or
on mouseUp
--put return after the selection
end mouseUp

they both seem to do the same thing.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

elanorb
Livecode Staff Member
Livecode Staff Member
Posts: 516
Joined: Fri Feb 24, 2006 9:45 am

Re: Triggering KeyPresses from buttons

Post by elanorb » Fri Mar 21, 2014 12:40 pm

Hi

I think when handling the return key you will need to check for the "return on tab" property yourself. Something like

on mouseUp
if the autoTab of field "input" is true then
select before field (the number of field "input" + 1)
else
put return into the selection
end if
end mouseUp

I hope that helps.

Kind regards

Elanor
Elanor Buchanan
Software Developer
LiveCode

DavJans
Posts: 270
Joined: Thu Dec 12, 2013 4:21 pm
Location: Spokane, WA USA

Re: Triggering KeyPresses from buttons

Post by DavJans » Fri Mar 21, 2014 3:33 pm

Elanor and Neil, You guys are wondefull, got it to work.

Code: Select all

on mouseUp
   Put the number of the selectedField into currentField
   if the autoTab of fld currentField is true then
      select the text of fld (currentField + 1)
      else
         put return into the selection
         end if
end mouseUp
Thank you much.
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

Post Reply

Return to “idea2app and Coding School”