-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathsimplekeycodes.nim
49 lines (38 loc) · 1.37 KB
/
simplekeycodes.nim
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
# Simple non-full-screen example that prints out keycode enums of the keys
# pressed on the keyboard.
#
# Note that although echo, write and the terminal module should not be used
# when using illwill in fullscreen mode, in non-fullscreen mode it's okay to
# use them. In such case illwill is typically used for non-blocking keyboard
# input only, so it's best to import only the functions needed for that, as
# shown below. This way there will be no symbol name clashes when importing
# the terminal module (e.g. the foreground and background color enums).
import os, terminal
from illwill import illwillInit, illwillDeinit, getKey, Key
proc exitProc() {.noconv.} =
illwillDeinit()
quit(0)
proc main() =
setControlCHook(exitProc)
illwillInit(fullscreen=false)
setForegroundColor(fgWhite)
setStyle({styleDim})
echo "-----------------------------------------------------------------"
resetAttributes()
setForegroundColor(fgYellow)
echo "Press keys/key combinations on the keyboard to view their keycode"
setForegroundColor(fgRed)
echo "Press Ctrl-C to quit"
setForegroundColor(fgWhite)
setStyle({styleDim})
echo "-----------------------------------------------------------------"
setForegroundColor(fgWhite)
setStyle({styleDim})
resetAttributes()
while true:
var key = getKey()
if key != Key.None:
echo key
else:
sleep(20)
main()