How can I tell F-keys and Accented chars apart in Keydown event?

On Windows, in a Keydown event, the F-Keys produce codes that overlap with normal character codes:

F1 generates CHR(&hC8)
F2 generates CHR(&hC9)

Typing generates CHR(&hC8)
Typing generates CHR(&hC9)

See the similarities?

So, how can I tell the two apart?

On the Mac, this problem is similar but less severe: Here, F-Key codes overlap with Control chars (e.g. both F9 and ctrl-P generate CHR(&h10), but at least those ctrl codes are hardly ever typed, whereas on Windows, any french user will curse at my application for not being able to tell french accented chars apart from F-Keys.

To clarify: In a TextField this of is little concern, but when filtering key presses in a Canvas or Window, I need to be able to tell F1 apart from so that I can react to them differently.

This has been discussed before and if I remember right there was no workaround :frowning:

It is indeed a big issue not to be abe to distinguish between accented letters and function keys. For instance, the Quebec French keyboard generates directly É, which maybe confused for F2 by Xojo. Probably because in English there are no accents :frowning: VB treats function keys much differently, with two byte codes containing a preceding zero.

Seems the keyboard object keycode make a distinction between function keys and alphabetic.
http://documentation.xojo.com/index.php/Keyboard

Maybe you can find a workaround there…

Keyboard.AsyncKeyDown() is the only way, but here you have to test every Fkey to see if the user pressed them or the accented char.

I’ve just filed a Feature Request #33276 requesting that KeyBoard return the raw Keycode.

Like in Keyboard.AsyncKeyDown ?
http://documentation.xojo.com/index.php/Keyboard.AsyncKeyDown

But this increases your level of complexity a great deal since the same key code may be different “keys” when using different keyboard layouts (as noted under KeyCodes on http://documentation.xojo.com/index.php/Keyboard)

I just tested. The Keyboard.AsyncKeyDown does return a physical map of the keyboard. The list of keys mentionned on the documentation is valid only for the US keyboard. On a French keyboard where a and q are switched, a is &h0C and q is &h00.

But for function keys it works fine,as they are the same in all keyboards.

It should be fairly easy in KeyDown to use Keyboard.AsyncKeyDown first to see if the key is a function key and for instance add chr(0) as prefix to Key, so it disambiguates accented characters and function keys, pretty much the same way VB does.

[quote=81948:@Michel Bujardet]I just tested. The Keyboard.AsyncKeyDown does return a physical map of the keyboard. The list of keys mentionned on the documentation is valid only for the US keyboard. On a French keyboard where a and q are switched, a is &h0C and q is &h00.
[/quote]
This is precisely the problem with key code :stuck_out_tongue:

What would be really useful is an “event record” of some kind - more like the web has for key events
http://documentation.xojo.com/index.php/KeyEvent
Whether thats in conjunction with a “character” that the key press generates or not I’m not sure (although it might be simpler in total)

But this issue is something we’re aware of