예제 #1
0
// Return first available unused keycode
func (x *X) UnusedKeycode() (C.KeyCode, error) {
	if x.unusedKeycode > 0 {
		return x.unusedKeycode, nil
	}

	var min_keycode C.int
	var max_keycode C.int
	C.XDisplayKeycodes(x.dpy, &min_keycode, &max_keycode)
	for i := min_keycode; i <= max_keycode; i++ {
		var keysyms_per_keycode C.int
		keysym := C.XGetKeyboardMapping(x.dpy, C.KeyCode(i), 1, &keysyms_per_keycode)
		if *keysym == 0 {
			x.unusedKeycode = C.KeyCode(i)
			return x.unusedKeycode, nil
		}
	}

	return 0, fmt.Errorf("Unable to find an unused keycode")
}
예제 #2
0
func (k *Keyboard) KeyDown(c KeyCode) bool {
	return gobool(C.keyboard_is_key_down(k.cptr, C.KeyCode(c)))
}