From dcefa88a048339f7311c3e2ce98217013117c739 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 7 Jun 2014 00:46:47 -0400 Subject: [PATCH] Fixed incorrect numpad handling on Windows Areas. --- area_windows.go | 24 ++++++++++++++++++++---- todo.md | 3 --- zconstants_windows_386.go | 1 + zconstants_windows_amd64.go | 1 + 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/area_windows.go b/area_windows.go index 344f43f..3e133f7 100644 --- a/area_windows.go +++ b/area_windows.go @@ -499,10 +499,10 @@ func areaKeyEvent(s *sysData, up bool, wparam _WPARAM, lparam _LPARAM) { scancode := byte((lparam >> 16) & 0xFF) ke.Modifiers = getModifiers() - if wparam == _VK_RETURN && (lparam & 0x01000000) != 0 { - // the above is special handling for numpad enter - // bit 24 of LPARAM (0x01000000) indicates right-hand keys - ke.ExtKey = NEnter + if extkey, ok := numpadextkeys[wparam]; (lparam & 0x01000000) == 0 && ok { + // the above is special handling for numpad keys to ignore the state of Num Lock and Shift; see http://blogs.msdn.com/b/oldnewthing/archive/2004/09/06/226045.aspx and https://github.com/glfw/glfw/blob/master/src/win32_window.c#L152 + // bit 24 of LPARAM (0x01000000) indicates right-hand keys; in our case "right-hand keys" means the separate buttons, so 0 means numpad + ke.ExtKey = extkey } else if extkey, ok := extkeys[wparam]; ok { ke.ExtKey = extkey } else if mod, ok := modonlykeys[wparam]; ok { @@ -524,6 +524,22 @@ func areaKeyEvent(s *sysData, up bool, wparam _WPARAM, lparam _LPARAM) { } } +// all mappings except the VK_RETURN one come from GLFW - https://github.com/glfw/glfw/blob/master/src/win32_window.c#L152 +var numpadextkeys = map[_WPARAM]ExtKey{ + _VK_HOME: N7, + _VK_UP: N8, + _VK_PRIOR: N9, + _VK_LEFT: N4, + _VK_CLEAR: N5, + _VK_RIGHT: N6, + _VK_END: N1, + _VK_DOWN: N2, + _VK_NEXT: N3, + _VK_INSERT: N0, + _VK_DELETE: NDot, + _VK_RETURN: NEnter, +} + var extkeys = map[_WPARAM]ExtKey{ _VK_ESCAPE: Escape, _VK_INSERT: Insert, diff --git a/todo.md b/todo.md index d00c94e..8cd15d6 100644 --- a/todo.md +++ b/todo.md @@ -36,6 +36,3 @@ ALL PLATFORMS: - TODO remember what this means - make all widths and heights parameters in constructors in the same place (or drop the ones in Window entirely?) - Message boxes that belong to agiven parent are still application-modal on all platforms except Mac OS X because the whole system waits... we'll need to use a channel for this, I guess :S - -- on Windows, Shift+(num pad key) triggers the shifted key code when num lock is off; will need to reorder key code tests on all platforms to fix this - - http://blogs.msdn.com/b/oldnewthing/archive/2004/09/06/226045.aspx diff --git a/zconstants_windows_386.go b/zconstants_windows_386.go index 304b175..69c9071 100644 --- a/zconstants_windows_386.go +++ b/zconstants_windows_386.go @@ -90,6 +90,7 @@ const _SW_SHOW = 5 const _SW_SHOWDEFAULT = 10 const _TRUE = 1 const _VK_ADD = 107 +const _VK_CLEAR = 12 const _VK_CONTROL = 17 const _VK_DELETE = 46 const _VK_DIVIDE = 111 diff --git a/zconstants_windows_amd64.go b/zconstants_windows_amd64.go index ab3cba2..3bae9b5 100644 --- a/zconstants_windows_amd64.go +++ b/zconstants_windows_amd64.go @@ -90,6 +90,7 @@ const _SW_SHOW = 5 const _SW_SHOWDEFAULT = 10 const _TRUE = 1 const _VK_ADD = 107 +const _VK_CLEAR = 12 const _VK_CONTROL = 17 const _VK_DELETE = 46 const _VK_DIVIDE = 111