rawdraw icon indicating copy to clipboard operation
rawdraw copied to clipboard

[Windows] Handling function keys needs information from msg.lParam in CNFGHandleInput()

Open pk240 opened this issue 4 years ago • 2 comments

There is some key overlap with the function keys on Windows. I noticed this with function key F2. It has keycode 0x71. The key 'q' also has this keycode.

The way to tell them apart lies in msg.lParam (in CNFGHandleInput()):

https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-keydown

Bits 16-23 of msg.lParam are the scan code.

Just to test it, I put this scancode in bDown and that makes it workable. (So then I test for two variables when handling keys)

What would you think of some kind of generalized approach? Like having the keyboard on Windows and Android all use the keycodes (and handling) of Linux? Or defining a bunch of globals like CNFG_KEY_F1 or CNFG_KEY_BS (but not for alphanumerics), or maybe having keycode be an enum?

I could try to write something like this, if you want.

pk240 avatar Nov 24 '21 16:11 pk240

I encountered this previously as well. You may notice the same issues when typing numbers on the numpad, using the arrow keys, or the context menu key.

We agreed back then that this should be fixed to make keys distinguishable, but I never got around to fixing it. Perhaps @cnlohr can chime in on his preferred way to approach a fix? A PR would be welcome!

CaiB avatar Nov 28 '21 06:11 CaiB

I'd def be up for accepting a PR on this.

cnlohr avatar Jan 18 '22 07:01 cnlohr

The problem appears to lie in the fact that the code uses tolower() which converts an uppercase letter to lowercase (note that this only happens if the letter is defined as uppercase by some predefined constraints). According to the Virtual Keycodes documentation (which is linked under wParam in the documentation page above), there isn't any noticeable overlap between the keycodes (the page lists in numerical order). The above function was probably used to provide cross-platform compatibility between Linux and Windows since, at least on my machine, Linux's Q keycode is 0x71. The best solution in this case would probably be to remove that function and include a list of macros defining that platform's keycodes

Kylogias avatar Aug 20 '22 20:08 Kylogias