Rockbox Technical Forums

Support and General Use => Plugins/Viewers => Topic started by: ipodclassic on January 05, 2018, 05:29:48 PM

Title: LUA -- check if key is pressed?
Post 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
Title: Re: LUA -- check if key is pressed?
Post by: __builtin on January 05, 2018, 05:57:07 PM
I haven't checked if it's available in lua, but try button_status().
Title: Re: LUA -- check if key is pressed?
Post by: ipodclassic on January 05, 2018, 07:22:53 PM
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 :-\
Title: Re: LUA -- check if key is pressed?
Post by: __builtin on January 05, 2018, 09:28:43 PM
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.
Title: Re: LUA -- check if key is pressed?
Post by: ipodclassic on January 06, 2018, 12:52:51 AM
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.
Title: Re: LUA -- check if key is pressed?
Post by: __builtin on January 06, 2018, 02:47:53 PM
For the sim you must use the numpad keys.
Title: Re: LUA -- check if key is pressed?
Post by: ipodclassic on January 06, 2018, 10:25:32 PM
This is the code I am using:
Code: [Select]
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

Code: [Select]
D
D
N
Title: Re: LUA -- check if key is pressed?
Post by: ipodclassic on January 09, 2018, 03:50:20 PM
Sorry... My mistake. Figured that now. Looks like every keyboard behaves in a different way.