Rockbox Technical Forums
Support and General Use => Plugins/Viewers => Topic started by: ipodclassic on January 05, 2018, 05:29:48 PM
-
Dear users,
Is there any way in LUA I can check if any key is pressed without pausing the program to wait for the key press?
Thanks in advance
-
I haven't checked if it's available in lua, but try button_status().
-
Thanks. Can you please tell me what should be the parameters? I tried setting different parameters within rb.button_status() but it doesn't give me proper output :-\
-
From C it takes no arguments and returns a mask of the buttons pressed. See your target's button-target.h file for the actual button names themselves.
-
Thanks. It works. Looks like i am having some trouble with the Simulator for my iPod Classic. It does not register all the keys for some reason.
-
For the sim you must use the numpad keys.
-
This is the code I am using:
next_action = rb.actions.ACTION_KBD_RIGHT
up_action = rb.actions.ACTION_KBD_UP
prev_action = rb.actions.ACTION_KBD_LEFT
down_action = rb.actions.ACTION_KBD_DOWN
select_action = rb.actions.ACTION_KBD_SELECT
safe_exit_action = rb.actions.ACTION_KBD_LEFT
----
----
----
local action = rb.get_action(rb.contexts.CONTEXT_KEYBOARD, -1)
if action == select_action then
printf("S")
elseif action == down_action then
printf("D")
elseif action == up_action then
printf("U")
elseif action == next_action then
printf("N")
elseif action == prev_action then
bRun = false
end
But only "S" or "N" gets printed as soon as the keys are pressed.
"D" and "U" does not display immediately. They only appear after "S" or "N" are pressed.
So for example if I press D twice and then press N then the output will be
D
D
N
-
Sorry... My mistake. Figured that now. Looks like every keyboard behaves in a different way.