I tried to post this a few days ago but my code contained the string "cmd./.ctrl" (without the dots), and the forum kept failing telling me it couldn't find the page every time I tried to post!. It turns out when you include this string (without the dots), it causes the forum to return 404. Who knew... LiveCode support figured it out, but now idea how
I had tried to post this as an example of using combination of keyDown and keyUp handlers, and which would likely obviate the need for flushEvents. This is a modification of my previous stack, maybe it will be helpful. The code registers and processes the key press on keyDown, and responses with user feedback in the keyUp message.
Code: Select all
local sKey -- assigning a value to this makes the stack ignore subsequent key-presses
local sResult -- store the result
constant kAllowedNums = "1,2,3,4"
constant kAllowedControlKeyCombos = "1,2,5"
on keyDown pKeyName
if sKey is not empty then exit to top -- ensures only 1st keyDown is acted on - until initKey is run
if pKeyName is in kAllowedNums and commandKey() <> "down" then
put pKeyName into sKey -- correct answer
else if pKeyName is not in kAllowedNums and commandKey() <> "down" then
put "Wrong answer!" into sKey -- wrong answer
end if
pass keyDown
end keyDown
on keyUp pKeyName
if pKeyName is in kAllowedControlKeyCombos and commandKey() = "down" then -- check for command or control key combos
put "c-" & pKeyName into sKey
end if
-- process result
if sKey = "Wrong answer!" then -- do stuff if wrong, but in this simple example it's the same action
put sKey into field "keyPressed"
else if "-" is in sKey then -- based on my code this signifies cmd or ctrl-key combo - but in this simple example it's the same action
put sKey into field "keyPressed"
else // correct answer
put sKey into field "keyPressed" -- action on success, would normally call a different handler
end if
end keyUp
command initKey
put empty into sKey -- this allow registering next key press
put "<Nothing>" into field "keyPressed" of me -- reset interface, would normally call a different handler
end initKey
Stam
-- EDIT: Simon from LC has tracked down the issue with not being able to submit posts with the string "cmd/ctrl" in them to a security resection and he likely can tweak this. Yay