/
keyboard.go
68 lines (59 loc) · 1.29 KB
/
keyboard.go
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
66
67
68
/**
*
* Keyboard IO library.
* For creating interesting CLI apps.
*
* Author: Timothy Lorens (tlorens@cyberdyne.org)
* https://github.com/tlorens
* http://www.cyberdyne.org/~icebrkr
*
*/
package keyboard
/*
#include "cgetkey.h"
*/
import "C"
const HOME = 149 // DOS Keycode #0 + #71
const END = 152 // DOS Keycode #0 + #79
const PG_UP = 153 // DOS Keycode #0 + #73
const PG_DN = 154 // DOS Keycode #0 + #81
const KEY_UP = 165 // DOS Keycode #0 + #72
const KEY_DN = 166 // DOS Keycode #0 + #80
const KEY_RT = 167 // DOS Keycode #0 + #77
const KEY_LF = 168 // DOS Keycode #0 + #75
/**
*
* ReadKey
*
* Reads a single keystroke and returns it's ASCII value.
* If a special key is pressed such as an arrow-key, it will process
* the ^] + ] return codes and return the ASCII value + 100.
*
* @return Integer
*
*/
func ReadKey() int {
var ch int
ch = int(C.readkey())
if ch == 27 { // ESC
if int(C.readkey()) == 91 { // [ bracket
ch = int(C.readkey()) + 100 // Add 100 to ASCII value.
}
}
return ch
}
/**
*
* RawKey
*
* Reads a single keystroke and returns it's ASCII value.
* Does nothing with special keys being pressed.
* You will have to read each character code and process them
* yourself.
*
* @return Integer
*
*/
func RawKey() int {
return int(C.readkey())
}