func areaKeyEvent(self C.id, e C.id, up bool, data unsafe.Pointer) C.BOOL { var ke KeyEvent keyCode := uintptr(C.keyCode(e)) ke, ok := fromKeycode(keyCode) if !ok { // no such key; modifiers by themselves are handled by -[self flagsChanged:] return C.NO } // either ke.Key or ke.ExtKey will be set at this point ke.Modifiers = parseModifiers(e) ke.Up = up return sendKeyEvent(self, ke, data) }
//export areaView_flagsChanged func areaView_flagsChanged(self C.id, e C.id, data unsafe.Pointer) C.BOOL { var ke KeyEvent // Mac OS X sends this event on both key up and key down. // Fortunately -[e keyCode] IS valid here, so we can simply map from key code to Modifiers, get the value of [e modifierFlags], and check if the respective bit is set or not — that will give us the up/down state keyCode := uintptr(C.keyCode(e)) mod, ok := keycodeModifiers[keyCode] // comma-ok form to avoid adding entries if !ok { // unknown modifier; ignore return C.NO } ke.Modifiers = parseModifiers(e) ke.Up = (ke.Modifiers & mod) == 0 ke.Modifier = mod // don't include the modifier in ke.Modifiers ke.Modifiers &^= mod return sendKeyEvent(self, ke, data) }