How to detect 3 key press combined with Shift in Firemonkey for any keyboard?


I’d like to detect Shift+3 in the Form’s KeyDown event. KeyChar contains ‘3’ when just the 3 key is pressed, but is modified to the Shift character when Shift is down (on my British keyboard it’s the ‘£’ symbol but for US keyboards it will be ‘#’ and OSX could be ‘"’ and so on). How can I detect this for any keyboard for Windows or Mac? The Key input variable is empty unfortunately. I looked for a function to convert a character to a virtual key code (such as Windows VkScanEx) but didn’t find anything for both Windows and OSX. I somehow need to convert the Shift modified character back into a ‘3’.
Here’s a relevant quote from the documentation.
"If a pressed key combination can be treated as a printable character or digit, then Key = 0 and KeyChar contains a pressed symbol"
This is the cause of my issue. I need to interpret the key press as a shortcut rather than a printable character. So I somehow need to get the virtual key value. This would not be a problem for Ctrl+3 because it would be interpreted as a shortcut and Key would have the correct non zero value. Unfortunately I need to detect Shift+3.
Note that on some keyboards (e.g. French) I would have the same problem without the Shift key being pressed since the numbers and symbols are reversed with the Shift key. I’d like to detect the 3 key being pressed whether or not Shift is pressed and on any keyboard.

Comments are closed.