Rockbox.org home
Downloads
Release release
Dev builds dev builds
Extras extras
themes themes
Documentation
Manual manual
Wiki wiki
Device Status device status
Support
Forums forums
Mailing lists mailing lists
IRC IRC
Development
Bugs bugs
Patches patches
Dev Guide dev guide
Search



Donate

Rockbox Technical Forums


Login with username, password and session length
Home Help Search Staff List Login Register
News:

Rockbox Ports are now being developed for various digital audio players!

+  Rockbox Technical Forums
|-+  Support and General Use
| |-+  Plugins/Viewers
| | |-+  LUA -- check if key is pressed?
« previous next »
  • Print
Pages: [1]

Author Topic: LUA -- check if key is pressed?  (Read 2755 times)

Offline ipodclassic

  • Member
  • *
  • Posts: 15
LUA -- check if key is pressed?
« 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
Logged

Offline __builtin

  • Developer
  • Member
  • *
  • Posts: 385
  • iPod 6G, c200v1 (RIP), e200v1 (RIP)
    • FWEI.TK
Re: LUA -- check if key is pressed?
« Reply #1 on: January 05, 2018, 05:57:07 PM »
I haven't checked if it's available in lua, but try button_status().
Logged
No support questions by PM, please.

Offline ipodclassic

  • Member
  • *
  • Posts: 15
Re: LUA -- check if key is pressed?
« Reply #2 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 :-\
Logged

Offline __builtin

  • Developer
  • Member
  • *
  • Posts: 385
  • iPod 6G, c200v1 (RIP), e200v1 (RIP)
    • FWEI.TK
Re: LUA -- check if key is pressed?
« Reply #3 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.
Logged
No support questions by PM, please.

Offline ipodclassic

  • Member
  • *
  • Posts: 15
Re: LUA -- check if key is pressed?
« Reply #4 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.
Logged

Offline __builtin

  • Developer
  • Member
  • *
  • Posts: 385
  • iPod 6G, c200v1 (RIP), e200v1 (RIP)
    • FWEI.TK
Re: LUA -- check if key is pressed?
« Reply #5 on: January 06, 2018, 02:47:53 PM »
For the sim you must use the numpad keys.
Logged
No support questions by PM, please.

Offline ipodclassic

  • Member
  • *
  • Posts: 15
Re: LUA -- check if key is pressed?
« Reply #6 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
« Last Edit: January 09, 2018, 10:10:48 AM by ipodclassic »
Logged

Offline ipodclassic

  • Member
  • *
  • Posts: 15
Re: LUA -- check if key is pressed?
« Reply #7 on: January 09, 2018, 03:50:20 PM »
Sorry... My mistake. Figured that now. Looks like every keyboard behaves in a different way.
Logged

  • Print
Pages: [1]
« previous next »
+  Rockbox Technical Forums
|-+  Support and General Use
| |-+  Plugins/Viewers
| | |-+  LUA -- check if key is pressed?
 

  • SMF 2.0.17 | SMF © 2019, Simple Machines
  • Rockbox Privacy Policy
  • XHTML
  • RSS
  • WAP2

Page created in 0.063 seconds with 15 queries.