summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/nigui.nim6
-rwxr-xr-xsrc/nigui/private/gtk3/platform_impl.nim6
-rwxr-xr-xsrc/nigui/private/windows/platform_impl.nim46
-rwxr-xr-xsrc/nigui/private/windows/windows.nim22
4 files changed, 64 insertions, 16 deletions
diff --git a/src/nigui.nim b/src/nigui.nim
index 09a71a0..9b419f0 100755
--- a/src/nigui.nim
+++ b/src/nigui.nim
@@ -131,6 +131,12 @@ type
Key_End
Key_PageUp
Key_PageDown
+ Key_ControlL
+ Key_ControlR
+ Key_AltL
+ Key_AltR
+ Key_ShiftL
+ Key_ShiftR
const
inactiveTimer* = 0
diff --git a/src/nigui/private/gtk3/platform_impl.nim b/src/nigui/private/gtk3/platform_impl.nim
index e63083c..c1adf55 100755
--- a/src/nigui/private/gtk3/platform_impl.nim
+++ b/src/nigui/private/gtk3/platform_impl.nim
@@ -77,6 +77,12 @@ proc pKeyvalToKey(keyval: cint): Key =
of 65367: Key_End
of 65365: Key_PageUp
of 65366: Key_PageDown
+ of 65505: Key_ShiftL
+ of 65506: Key_ShiftR
+ of 65507: Key_ControlL
+ of 65508: Key_ControlR
+ of 65513: Key_AltL
+ of 65514: Key_AltR
else: cast[Key](keyval.unicodeToUpper)
proc pWindowKeyPressSignal(widget: pointer, event: var GdkEventKey, data: pointer): bool {.cdecl.} =
diff --git a/src/nigui/private/windows/platform_impl.nim b/src/nigui/private/windows/platform_impl.nim
index 1f76e6a..6cff721 100755
--- a/src/nigui/private/windows/platform_impl.nim
+++ b/src/nigui/private/windows/platform_impl.nim
@@ -208,19 +208,28 @@ proc pCommonWndProc(hWnd: pointer, uMsg: int32, wParam, lParam: pointer): pointe
discard
result = DefWindowProcA(hWnd, uMsg, wParam, lParam)
-proc pVirtualKeyToKey(keyval: int): Key =
+proc pVirtualKeyToKey(keyval, scancode: int32): Key =
case keyval
- of 33: Key_PageUp
- of 34: Key_PageDown
- of 35: Key_End
- of 36: Key_Home
- of 37: Key_Left
- of 38: Key_Up
- of 39: Key_Right
- of 40: Key_Down
- of 45: Key_Insert
- of 46: Key_Delete
- else: cast[Key](keyval.unicodeToUpper)
+ of VK_CONTROL, VK_SHIFT, VK_MENU:
+ case MapVirtualKeyW(scancode, MAPVK_VSC_TO_VK_EX)
+ of VK_LCONTROL: result = Key_ControlL
+ of VK_RCONTROL: result = Key_ControlR
+ of VK_LSHIFT: result = Key_ShiftL
+ of VK_RSHIFT: result = Key_ShiftR
+ of VK_LMENU: result = Key_AltL
+ of VK_RMENU: result = Key_AltR
+ else: discard
+ of VK_PRIOR: result = Key_PageUp
+ of VK_NEXT: result = Key_PageDown
+ of VK_END: result = Key_End
+ of VK_HOME: result = Key_Home
+ of VK_LEFT: result = Key_Left
+ of VK_UP: result = Key_Up
+ of VK_RIGHT: result = Key_Right
+ of VK_DOWN: result = Key_Down
+ of VK_INSERT: result = Key_Insert
+ of VK_DELETE: result = Key_Delete
+ else: result = cast[Key](keyval.unicodeToUpper)
proc pHandleWMKEYDOWNOrWMCHAR(window: Window, control: Control, unicode: int): bool =
var windowEvent = new WindowKeyEvent
@@ -253,11 +262,18 @@ proc pHandleWMKEYDOWNOrWMCHAR(window: Window, control: Control, unicode: int): b
proc pHandleWMKEYDOWN(window: Window, control: Control, wParam, lParam: pointer): bool =
if not GetKeyboardState(pKeyState): pRaiseLastOSError()
- pKeyDownKey = pVirtualKeyToKey(cast[int](wParam))
# Save the key for WM_CHAR, because WM_CHAR only gets the key combined with the dead key state
var widestring = newString(2)
- let scancode = int32((cast[int](lParam) shr 8) and 0xFFFFFF00)
- if scancode == 10496:
+ let scancode = (cast[int32](lParam) and 0x00FF0000) shr 16
+
+ # echo scancode
+ # echo cast[int](wParam)
+
+
+ pKeyDownKey = pVirtualKeyToKey(cast[int32](wParam), scancode)
+
+
+ if cast[int](wParam) == VK_OEM_5:
# When the dead key "^" on German keyboard is pressed, don't call ToUnicode(), because this would destroy the dead key state
pKeyDownKey = Key_Circumflex
return pHandleWMKEYDOWNOrWMCHAR(window, control, 0)
diff --git a/src/nigui/private/windows/windows.nim b/src/nigui/private/windows/windows.nim
index 473b727..3bf3515 100755
--- a/src/nigui/private/windows/windows.nim
+++ b/src/nigui/private/windows/windows.nim
@@ -89,8 +89,27 @@ const
SW_RESTORE* = 9
SWP_NOMOVE* = 2
SWP_NOSIZE* = 1
+ VK_SHIFT* = 16
VK_CONTROL* = 17
VK_MENU* = 18
+ VK_PRIOR* = 33
+ VK_NEXT* = 34
+ VK_END* = 35
+ VK_HOME* = 36
+ VK_LEFT* = 37
+ VK_UP* = 38
+ VK_RIGHT* = 39
+ VK_DOWN* = 40
+ VK_SNAPSHOT* = 44
+ VK_INSERT* = 45
+ VK_DELETE* = 46
+ VK_LSHIFT* = 160
+ VK_RSHIFT* = 161
+ VK_LCONTROL* = 162
+ VK_RCONTROL* = 163
+ VK_LMENU* = 164
+ VK_RMENU* = 165
+ VK_OEM_5* = 220
WM_ACTIVATE* = 0x0006
WM_CHANGEUISTATE* = 0x0127
WM_CHAR* = 258
@@ -165,6 +184,7 @@ const
GMEM_MOVEABLE* = 2
PixelFormat32bppARGB* = 2498570
ImageLockModeWrite* = 2
+ MAPVK_VSC_TO_VK_EX* = 3
@@ -402,7 +422,7 @@ proc CloseClipboard*(): bool {.importc: "CloseClipboard", libUser32.}
proc GetClipboardData*(uFormat: int32): pointer {.importc: "GetClipboardData", libUser32.}
proc SetClipboardData*(uFormat: int32, hMem: pointer): pointer {.importc: "SetClipboardData", libUser32.}
proc EmptyClipboard*(): bool {.importc: "EmptyClipboard", libUser32.}
-# proc MapVirtualKeyW*(uCode, uMapType: int32): int32 {.importc: "MapVirtualKeyW", libUser32.}
+proc MapVirtualKeyW*(uCode, uMapType: int32): int32 {.importc: "MapVirtualKeyW", libUser32.}
when defined(cpu64):
# Only available on 64-bit Windows: