[Vm-dev] [OpenSmalltalk/opensmalltalk-vm] Keyboard Event issues on Windows (#42)

Nicolas Cellier notifications at github.com
Fri Dec 13 23:09:05 UTC 2019


Note about Ctrl+A/Z: AFAIU, it's what the console app were expected in the ages, so our OS still carry this tribute to legacy...

See how we have to workaround on linux:
https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/abf05549bd377106f27600a293d79f75a59e705e/platforms/unix/vm-display-X11/sqUnixX11.c#L2065

Who is turning the keysym into 1 to: 26 charCode?
https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/abf05549bd377106f27600a293d79f75a59e705e/platforms/unix/vm-display-X11/sqUnixX11.c#L2049
See https://linux.die.net/man/3/xlookupstring

I also mentionned this in issue #396 

So we might want to do something similar on Windows? (and Mac OS?)
For Win32, see https://docs.microsoft.com/en-us/windows/win32/learnwin32/keyboard-input

MSDN page above explicitely explains that CTRL+A/Z are translated to ASCII control character in the `VM_CHAR` event (as I suggested in preliminary comment, for legacy console app).
It also does not recommend handling CTRL+... or ALT+... thru `WM_CHAR` event, this is not the idiomatic handling on this platform.
And the doc is right - see why below.

The equivalent of linux keysym is the virtual key code (`VK_*`) passed thru wParam in `WM_KEYDOWN` event.
https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/d58235ca011b9a8f8344814b66d9f9d6428c963f/platforms/win32/vm/sqWin32Window.c#L1262

The problem is that we effectively get the keycode in case of `WM_KEYDOWN` event, but not in case of `VM_CHAR` event: `msg->wParam` holds an UTF-16 Unicode character the doc says...

So, IMO, we should better generate an extra OpenSmalltalk `EventKeyChar` event in response to `WM_KEYDOWN` event when we detect a CTRL down status, and filter out the event in case of `VM_CHAR` with CRTL down...

Note that Pharo VM uses `MapVirtualKey` with `MAPVK_VSC_TO_VK` to handle ctrl+char
https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/d58235ca011b9a8f8344814b66d9f9d6428c963f/platforms/win32/vm/sqWin32Window.c#L1319
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-mapvirtualkeya
Though it's not clear where the usage of `msg->lParam` comes from (`MapVirtualKey` expects a scan code, which is low level keyboard code and will return a VK code that fortunately matches ASCII for A to Z keys...), I've not seen it documented in official MSDN, it would be good to have a link documenting it.
It's not the way that MSDN (and I) recommended above, but might eventually work (I'm not in a position to understand if there are other side effects...)




-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/42#issuecomment-565643908
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20191213/62f1390b/attachment.html>


More information about the Vm-dev mailing list