Page 1 of 1

Triggering KeyPresses from buttons

Posted: Thu Mar 06, 2014 11:39 am
by LCNeil
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 90 times
Kind Regards,


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

Re: Triggering KeyPresses from buttons

Posted: Thu Mar 06, 2014 5:45 pm
by DavJans
Thank you Neil

Re: Triggering KeyPresses from buttons

Posted: Wed Mar 19, 2014 6:45 pm
by DavJans
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"

Re: Triggering KeyPresses from buttons

Posted: Thu Mar 20, 2014 11:36 am
by LCNeil
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
——

Re: Triggering KeyPresses from buttons

Posted: Thu Mar 20, 2014 4:24 pm
by DavJans
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.

Re: Triggering KeyPresses from buttons

Posted: Thu Mar 20, 2014 6:47 pm
by elanorb
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

Re: Triggering KeyPresses from buttons

Posted: Thu Mar 20, 2014 7:24 pm
by DavJans
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.

Re: Triggering KeyPresses from buttons

Posted: Fri Mar 21, 2014 12:40 pm
by elanorb
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

Re: Triggering KeyPresses from buttons

Posted: Fri Mar 21, 2014 3:33 pm
by DavJans
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.