Triggering KeyPresses from buttons
Moderators: LCNeil, heatherlaine, kevinmiller, elanorb
Triggering KeyPresses from buttons
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.
Kind Regards,
Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
——
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.
Kind Regards,
Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
——
Re: Triggering KeyPresses from buttons
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
Re: Triggering KeyPresses from buttons
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
it gives me an error
"button "Button": execution error at line 2 (Handler: can't find handler) near "rawKeyDown", char 1"
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
"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
Re: Triggering KeyPresses from buttons
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
——
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
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.
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
Re: Triggering KeyPresses from buttons
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
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
Software Developer
LiveCode
Re: Triggering KeyPresses from buttons
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.
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
Re: Triggering KeyPresses from buttons
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
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
Software Developer
LiveCode
Re: Triggering KeyPresses from buttons
Elanor and Neil, You guys are wondefull, got it to work.
Thank you much.
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
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här