1
Scripting Q&A / Double Press issues
« on: July 11, 2019, 05:25:34 PM »
This script should disable all keys, and log if there was a single or double keypress within 3 seconds.
When you run this script, I'd expect you'd be unable to navigate out of the menu.
Single presses are ignored.
But when you double press, it responds as a single press...
How's that possible with return false on all key events?
When you run this script, I'd expect you'd be unable to navigate out of the menu.
Single presses are ignored.
But when you double press, it responds as a single press...
How's that possible with return false on all key events?
Code: [Select]
-- Double Press
-- Not working
key_counter = 0
function check_double_press()
sleep(3)
if(key_counter == 2) then
-- Double press
display.notify_box(tostring(key_counter))
elseif(key_counter == 1) then
-- Single press
display.notify_box(tostring(key_counter))
end
key_counter = 0
return false
end
event.keypress = function(k)
key_counter = key_counter + 1
if(key_counter == 1) then
task.create(function()
check_double_press()
end)
end
-- Don't respond to any keys
return false
end