-
Notifications
You must be signed in to change notification settings - Fork 0
/
norns-kcode-test.lua
65 lines (51 loc) · 1.17 KB
/
norns-kcode-test.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
-- Manually test potential changes.
-- See https://github.com/monome/norns/issues/1657
local state = {
kcode = {
key = nil,
value = nil,
code_to_char = nil
},
kchar = {
ch = nil,
}
}
function init()
redraw()
end
function redraw()
screen.clear()
screen.move(0, 8)
screen.text("Last calls to...")
screen.move(0, 24)
screen.text("keyboard.code(" ..
stringify(state.kcode.key) .. ", " ..
stringify(state.kcode.value) .. ")"
)
screen.move(0, 32)
screen.text(" code_to_char(...) = " ..
stringify(state.kcode.code_to_char)
)
screen.move(0, 48)
screen.text("keyboard.char(" ..
stringify(state.kchar.ch) .. ")"
)
screen.update()
end
function stringify(s)
if type(s) ~= "string" then
return tostring(s)
end
local prefix = (s == '\\' or s == "'") and '\\' or ''
return "'" .. prefix .. s .. "'"
end
function keyboard.code(key, value)
state.kcode.key = key
state.kcode.value = value
state.kcode.code_to_char = keyboard.code_to_char(key)
redraw()
end
function keyboard.char(ch)
state.kchar.ch = ch
redraw()
end