-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkeyboard.go
81 lines (62 loc) · 1.43 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
69
70
71
72
73
74
75
76
77
78
79
80
81
package sdl
import (
"reflect"
"unsafe"
)
// #include <SDL.h>
import "C"
type Keysym struct {
Scancode Scancode
Sym Keycode
Mod uint16
Unicode uint32
}
func (ks *Keysym) c() *C.SDL_Keysym {
return (*C.SDL_Keysym)(unsafe.Pointer(ks))
}
func GetKeyboardFocus() *Window {
return &Window{C.SDL_GetKeyboardFocus()}
}
func GetKeyboardState() []uint8 {
var n C.int
s := C.SDL_GetKeyboardState(&n)
return *(*[]uint8)(unsafe.Pointer(&reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(s)),
Len: int(n),
Cap: int(n),
}))
}
func GetModState() Keymod {
return Keymod(C.SDL_GetModState())
}
func (s Scancode) GetKey() Keycode {
return Keycode(C.SDL_GetKeyFromScancode(s.c()))
}
func (k Keycode) GetScancode() Scancode {
return Scancode(C.SDL_GetScancodeFromKey(k.c()))
}
func (s Scancode) GetName() string {
return C.GoString(C.SDL_GetScancodeName(s.c()))
}
func GetScancodeFromName(name string) Scancode {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return Scancode(C.SDL_GetScancodeFromName(cname))
}
func (k Keycode) GetName() string {
return C.GoString(C.SDL_GetKeyName(k.c()))
}
func GetKeyFromName(name string) Keycode {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return Keycode(C.SDL_GetKeyFromName(cname))
}
func StartTextInput() {
C.SDL_StartTextInput()
}
func StopTextInput() {
C.SDL_StopTextInput()
}
func SetTextInputRect(r *Rect) {
C.SDL_SetTextInputRect(r.c())
}