summaryrefslogtreecommitdiff
path: root/apps/plugins/lua_scripts/print_buttons.lua
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lua_scripts/print_buttons.lua')
-rw-r--r--apps/plugins/lua_scripts/print_buttons.lua70
1 files changed, 70 insertions, 0 deletions
diff --git a/apps/plugins/lua_scripts/print_buttons.lua b/apps/plugins/lua_scripts/print_buttons.lua
new file mode 100644
index 0000000000..1b488ddd64
--- /dev/null
+++ b/apps/plugins/lua_scripts/print_buttons.lua
@@ -0,0 +1,70 @@
1-- bilgus 4/2021
2require "buttons"
3local BUTTON_NONE = 0
4
5local function decode_ord_btn(btn)
6 local btntxt = ""
7 for k, v in pairs(rb.buttons) do
8 if btn > BUTTON_NONE and v ~= BUTTON_NONE and bit.band(btn, v) == v then
9 if #btntxt > 0 then
10 btntxt = btntxt .. " | "
11 end
12 btntxt = btntxt .. k
13 end
14 end
15 if btntxt == "" then return nil end
16 return btntxt
17end
18
19local _, w, h = rb.font_getstringsize("W", rb.FONT_UI)
20local max_lines = rb.LCD_HEIGHT / h - 1
21
22button_text = {}
23for k, v in pairs(rb.buttons) do
24 button_text[v] = k
25end
26
27--Add the system button codes to the button_text table
28for k, v in pairs(rb) do
29 if string.find(k or "", "SYS_", 1, true) and type(v) == "number" then
30 button_text[v] = k
31 end
32end
33
34local s = {[1] = "Buttons Found:"}
35for k, v in pairs(button_text) do
36 table.insert(s, tostring(k) .. " : " .. tostring(v))
37end
38rb.splash_scroller(rb.HZ, table.concat(s, "\n"))
39
40button_text[BUTTON_NONE] = " "
41
42local lastbtn = BUTTON_NONE
43local lastkey = BUTTON_NONE
44local s_t = {"Press same button 3x to exit"}
45local keyrpt = 0
46
47repeat
48
49 local btn
50 if lastbtn == BUTTON_NONE then
51 btn = rb.button_get(true)
52 else
53 btn = rb.button_get_w_tmo(rb.HZ)
54 end
55
56 if btn ~= lastkey then
57 table.insert(s_t, 1, (button_text[btn] or decode_ord_btn(btn) or "unknown " .. tostring (btn)))
58 end
59
60 if btn == lastbtn then keyrpt = keyrpt + 1 end
61 if button_text[btn] then lastbtn = btn end
62 lastkey = btn
63
64 rb.splash_scroller(-2, table.concat(s_t, "\n"))
65
66 if #s_t > max_lines then
67 table.remove(s_t)
68 end
69
70until keyrpt >= 2