Added the proper provision for numeric keypad entry.
This commit is contained in:
parent
a038934ffb
commit
84450cfa64
17
area_unix.go
17
area_unix.go
|
@ -189,9 +189,11 @@ func doKeyEvent(widget *C.GtkWidget, event *C.GdkEvent, data C.gpointer, up bool
|
|||
} else if mod, ok := modonlykeys[keyval]; ok {
|
||||
// modifier keys don't seem to be set on their initial keypress; set them here
|
||||
ke.Modifiers |= mod
|
||||
} else if key, ok := scancodeMap[uintptr(e.hardware_keycode) - 8]; ok {
|
||||
} else if xke, ok := fromScancode(uintptr(e.hardware_keycode) - 8); ok {
|
||||
// see events_notdarwin.go for details of the above map lookup
|
||||
ke.Key = key
|
||||
// one of these will be nonzero
|
||||
ke.Key = xke.Key
|
||||
ke.ExtKey = xke.ExtKey
|
||||
} else { // no match
|
||||
// TODO really stop here? [or should we handle modifiers?]
|
||||
return false // pretend unhandled
|
||||
|
@ -281,17 +283,6 @@ var extkeys = map[C.guint]ExtKey{
|
|||
C.GDK_KEY_F10: F10,
|
||||
C.GDK_KEY_F11: F11,
|
||||
C.GDK_KEY_F12: F12,
|
||||
// numeric keypad equivalents:
|
||||
C.GDK_KEY_KP_Insert: Insert,
|
||||
C.GDK_KEY_KP_Delete: Delete,
|
||||
C.GDK_KEY_KP_Home: Home,
|
||||
C.GDK_KEY_KP_End: End,
|
||||
C.GDK_KEY_KP_Page_Up: PageUp,
|
||||
C.GDK_KEY_KP_Page_Down: PageDown,
|
||||
C.GDK_KEY_KP_Up: Up,
|
||||
C.GDK_KEY_KP_Down: Down,
|
||||
C.GDK_KEY_KP_Left: Left,
|
||||
C.GDK_KEY_KP_Right: Right,
|
||||
}
|
||||
|
||||
// sanity check
|
||||
|
|
|
@ -1137,5 +1137,6 @@ There are a few loose ends:
|
|||
* Can the OS X key codes be used to differentiate between numpad keys and non-numpad keys regardless of num lock state? If so, we can safely differentiate between the two, and can get rid of that arbitrary restriction.
|
||||
* TODO
|
||||
* Can we also use scancodes for the numeric keypad, **including** the numeric keypad / key? GDK keysyms have Num Lock interpreted; we don't want that. This is just adding the scancodes for the numeric keypad to our test above...
|
||||
* TODO
|
||||
* We only need to worry about the number keys and ., it seems; everything else is unaffected by Num Lock (and uses extended scancodes, so.)
|
||||
* Okay, the numeric keys and . use the same scancodes and evdev key code values, so we can handle them with scancodes too.
|
||||
* The GLFW source does not use the scancode 0x2B for \, claiming that it only exists on US keyboards (instead it uses one of the OEM virtual key codes on Windows). This goes against the Scan Codes Demystified page, which says that on international keyboards, that would be another key (with region-specific label) underneath and to the right of what would be the [ and ] keys on a US keyboard. This appears to be true in some cases; in others, the extra key is to the left of Backspace instead. Either way, this is close enough to the \ key's position on a US keyboard that we can just go ahead and use 0x2B anyway.
|
||||
|
|
|
@ -14,10 +14,12 @@ Wayland is guaranteed to give the same result (thanks ebassi in irc.gimp.net/#gt
|
|||
On Linux, where evdev is used instead of polling scancodes directly from the keyboard, evdev's typewriter section key code constants are the same as scancodes anyway, so the rules above apply.
|
||||
Typewriter section scancodes are the same across international keyboards with some exceptions that have been accounted for (see KeyEvent's documentation); see http://www.quadibloc.com/comp/scan.htm for details.
|
||||
Non-typewriter keys can be handled safely using constants provided by the respective backend API.
|
||||
|
||||
Because GTK+ keysyms may or may not obey Num Lock, we also handle the 0-9 and . keys on the numeric keypad with scancodes (they match too).
|
||||
*/
|
||||
|
||||
// use uintptr to be safe; the size of the scancode/hardware key code field on each platform is different
|
||||
var scancodeMap = map[uintptr]byte{
|
||||
var scancodeKeys = map[uintptr]byte{
|
||||
0x02: '1',
|
||||
0x03: '2',
|
||||
0x04: '3',
|
||||
|
@ -70,3 +72,29 @@ var scancodeMap = map[uintptr]byte{
|
|||
0x35: '/',
|
||||
0x39: ' ',
|
||||
}
|
||||
|
||||
type scancodeExtKeys = map[uintptr]ExtKey{
|
||||
/* 0x47: N7,
|
||||
0x48: N8,
|
||||
0x49: N9,
|
||||
0x4B: N4,
|
||||
0x4C: N5,
|
||||
0x4D: N6,
|
||||
0x4F: N1,
|
||||
0x50: N2,
|
||||
0x51: N3,
|
||||
0x52: N0,
|
||||
0x53: NDot,
|
||||
*/}
|
||||
|
||||
func fromScancode(scancode uintptr) (ke KeyEvent, ok bool) {
|
||||
if key, ok := scancodeKeys[scancode]; ok {
|
||||
ke.Key = key
|
||||
return ke, true
|
||||
}
|
||||
if extkey, ok := scancodeExtKeys[scancode]; ok {
|
||||
ke.ExtKey = extkey
|
||||
return ke, true
|
||||
}
|
||||
return ke, false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue