Пример #1
0
func processKey(env *C.JNIEnv, e *C.AInputEvent) {
	deviceID := C.AInputEvent_getDeviceId(e)
	if deviceID == 0 {
		// Software keyboard input, leaving for scribe/IME.
		return
	}

	k := key.Event{
		Rune: rune(C.getKeyRune(env, e)),
		Code: convAndroidKeyCode(int32(C.AKeyEvent_getKeyCode(e))),
	}
	switch C.AKeyEvent_getAction(e) {
	case C.AKEY_STATE_DOWN:
		k.Direction = key.DirPress
	case C.AKEY_STATE_UP:
		k.Direction = key.DirRelease
	default:
		k.Direction = key.DirNone
	}
	// TODO(crawshaw): set Modifiers.
	eventsIn <- k
}
Пример #2
0
func sendKeyEvent(hwnd HWND, uMsg uint32, wParam, lParam uintptr) (lResult uintptr) {
	e := key.Event{
		Rune:      readRune(uint32(wParam), uint8(lParam>>16)),
		Code:      convVirtualKeyCode(uint32(wParam)),
		Modifiers: keyModifiers(),
	}
	switch uMsg {
	case _WM_KEYDOWN:
		const prevMask = 1 << 30
		if repeat := lParam&prevMask == prevMask; repeat {
			e.Direction = key.DirNone
		} else {
			e.Direction = key.DirPress
		}
	case _WM_KEYUP:
		e.Direction = key.DirRelease
	default:
		panic(fmt.Sprintf("win32: unexpected key message: %d", uMsg))
	}

	KeyEvent(hwnd, e)
	return 0
}