stardot / b-em

An opensource BBC Micro emulator for Win32 and Linux
http://stardot.org.uk/forums/viewtopic.php?f=4&t=10823
GNU General Public License v2.0
112 stars 56 forks source link

Alt-Graph Key-modifier ignored on Windows #194

Open egrath opened 1 year ago

egrath commented 1 year ago

Symptom: When using the logical Keyboard mapping on Windows, symbols which are on the tertiary level (like the @-symbol on German keyboards which is accessed with Alt-Gr+Q) are not recognized properly.

From what i can see in the in the logs, pressing Alt-Gr+Q is recognized but produces no character:

Alt-Gr press and hold:

08/04/2023 09:42:49 DEBUG keyboard: key down event, keycode=217:LCTRL, modifiers=0202
08/04/2023 09:42:49 DEBUG keyboard: key_paste_add_combo vkey=&aa, shift=0, ctrl=1
08/04/2023 09:42:49 DEBUG keyboard: key_paste_add_vkey, vkey1=&f1, vkey2=&aa
08/04/2023 09:42:49 DEBUG keyboard: key down event, keycode=220:ALTGR, modifiers=0242
08/04/2023 09:42:49 DEBUG keyboard: key_paste_poll next vkey=&f1
08/04/2023 09:42:49 DEBUG keyboard: key_paste_add_combo vkey=&aa, shift=0, ctrl=1

Q press and release:

08/04/2023 09:42:52 DEBUG keyboard: key down event, keycode=17:Q, modifiers=0242
08/04/2023 09:42:52 DEBUG keyboard: key char event, keycode=17:Q, unichar=113
08/04/2023 09:42:52 DEBUG keyboard: checking key action 0:break codes 17<>58, alt 1<>0
08/04/2023 09:42:52 DEBUG keyboard: checking key action 1:full-Speed codes 17<>80, alt 1<>0
08/04/2023 09:42:52 DEBUG keyboard: checking key action 2:pause codes 17<>81, alt 1<>0
08/04/2023 09:42:52 DEBUG keyboard: checking key action 3:full-screen1 codes 17<>57, alt 1<>0
08/04/2023 09:42:52 DEBUG keyboard: checking key action 4:debug-break codes 17<>56, alt 1<>0
08/04/2023 09:42:52 DEBUG keyboard: checking key action 5:full-screen2 codes 17<>67, alt 1<>1
08/04/2023 09:42:52 DEBUG keyboard: set_key_logical keycode=17, unichar=113, state=1
08/04/2023 09:42:52 DEBUG keyboard: key_paste_add_combo vkey=&10, shift=0, ctrl=1
08/04/2023 09:42:52 DEBUG keyboard: key_paste_add_vkey, vkey1=&d1, vkey2=&10
08/04/2023 09:42:52 DEBUG keyboard: key_paste_poll next vkey=&d1
08/04/2023 09:42:52 DEBUG keyboard: key_paste_poll down vkey=&10
08/04/2023 09:42:52 DEBUG keyboard: key up event, keycode=17:Q, modifiers=0242
08/04/2023 09:42:52 DEBUG keyboard: checking key action 0:break codes 17<>58, alt 1<>0
08/04/2023 09:42:52 DEBUG keyboard: checking key action 1:full-Speed codes 17<>80, alt 1<>0
08/04/2023 09:42:52 DEBUG keyboard: checking key action 2:pause codes 17<>81, alt 1<>0
08/04/2023 09:42:52 DEBUG keyboard: checking key action 3:full-screen1 codes 17<>57, alt 1<>0
08/04/2023 09:42:52 DEBUG keyboard: checking key action 4:debug-break codes 17<>56, alt 1<>0
08/04/2023 09:42:52 DEBUG keyboard: checking key action 5:full-screen2 codes 17<>67, alt 1<>1
08/04/2023 09:42:52 DEBUG keyboard: set_key_logical keycode=17, unichar=113, state=0
08/04/2023 09:42:52 DEBUG keyboard: key_paste_add_vkey, vkey1=&d0, vkey2=&10
08/04/2023 09:42:52 DEBUG keyboard: key_paste_poll next vkey=&d0
08/04/2023 09:42:52 DEBUG keyboard: key_paste_poll up vkey=&10
08/04/2023 09:42:52 DEBUG keyboard: key_paste_add_combo vkey=&aa, shift=0, ctrl=1

Alt-Gr release:

08/04/2023 09:42:54 DEBUG keyboard: key up event, keycode=217:LCTRL, modifiers=0240
08/04/2023 09:42:54 DEBUG keyboard: key_paste_add_combo vkey=&aa, shift=0, ctrl=0
08/04/2023 09:42:54 DEBUG keyboard: key_paste_add_vkey, vkey1=&f0, vkey2=&aa
08/04/2023 09:42:54 DEBUG keyboard: checking key action 0:break codes 217<>58, alt 1<>0
08/04/2023 09:42:54 DEBUG keyboard: checking key action 1:full-Speed codes 217<>80, alt 1<>0
08/04/2023 09:42:54 DEBUG keyboard: checking key action 2:pause codes 217<>81, alt 1<>0
08/04/2023 09:42:54 DEBUG keyboard: checking key action 3:full-screen1 codes 217<>57, alt 1<>0
08/04/2023 09:42:54 DEBUG keyboard: checking key action 4:debug-break codes 217<>56, alt 1<>0
08/04/2023 09:42:54 DEBUG keyboard: checking key action 5:full-screen2 codes 217<>67, alt 1<>1
08/04/2023 09:42:54 DEBUG keyboard: set_key_logical keycode=217, unichar=0, state=0
08/04/2023 09:42:54 DEBUG keyboard: key up event, keycode=220:ALTGR, modifiers=0200
08/04/2023 09:42:54 DEBUG keyboard: key_paste_poll next vkey=&f0
08/04/2023 09:42:54 DEBUG keyboard: key_paste_add_combo vkey=&aa, shift=0, ctrl=0

For reference, this is a Q-Key(press/release) on a German keyboard without Alt-Gr:

08/04/2023 09:47:49 DEBUG keyboard: key down event, keycode=17:Q, modifiers=0200
08/04/2023 09:47:49 DEBUG keyboard: key char event, keycode=17:Q, unichar=113
08/04/2023 09:47:49 DEBUG keyboard: checking key action 0:break codes 17<>58, alt 0<>0
08/04/2023 09:47:49 DEBUG keyboard: checking key action 1:full-Speed codes 17<>80, alt 0<>0
08/04/2023 09:47:49 DEBUG keyboard: checking key action 2:pause codes 17<>81, alt 0<>0
08/04/2023 09:47:49 DEBUG keyboard: checking key action 3:full-screen1 codes 17<>57, alt 0<>0
08/04/2023 09:47:49 DEBUG keyboard: checking key action 4:debug-break codes 17<>56, alt 0<>0
08/04/2023 09:47:49 DEBUG keyboard: checking key action 5:full-screen2 codes 17<>67, alt 0<>1
08/04/2023 09:47:49 DEBUG keyboard: set_key_logical keycode=17, unichar=113, state=1
08/04/2023 09:47:49 DEBUG keyboard: key_paste_add_combo vkey=&10, shift=0, ctrl=0
08/04/2023 09:47:49 DEBUG keyboard: key_paste_add_vkey, vkey1=&d1, vkey2=&10
08/04/2023 09:47:49 DEBUG keyboard: key_paste_poll next vkey=&d1
08/04/2023 09:47:49 DEBUG keyboard: key_paste_poll down vkey=&10
08/04/2023 09:47:49 DEBUG keyboard: key up event, keycode=17:Q, modifiers=0200
08/04/2023 09:47:49 DEBUG keyboard: checking key action 0:break codes 17<>58, alt 0<>0
08/04/2023 09:47:49 DEBUG keyboard: checking key action 1:full-Speed codes 17<>80, alt 0<>0
08/04/2023 09:47:49 DEBUG keyboard: checking key action 2:pause codes 17<>81, alt 0<>0
08/04/2023 09:47:49 DEBUG keyboard: checking key action 3:full-screen1 codes 17<>57, alt 0<>0
08/04/2023 09:47:49 DEBUG keyboard: checking key action 4:debug-break codes 17<>56, alt 0<>0
08/04/2023 09:47:49 DEBUG keyboard: checking key action 5:full-screen2 codes 17<>67, alt 0<>1
08/04/2023 09:47:49 DEBUG keyboard: set_key_logical keycode=17, unichar=113, state=0
08/04/2023 09:47:49 DEBUG keyboard: key_paste_add_vkey, vkey1=&d0, vkey2=&10
08/04/2023 09:47:49 DEBUG keyboard: key_paste_poll next vkey=&d0
08/04/2023 09:47:49 DEBUG keyboard: key_paste_poll up vkey=&10
08/04/2023 09:47:49 DEBUG keyboard: key_paste_add_combo vkey=&aa, shift=0, ctrl=0

This issue does not occur on Linux and Macintosh, only Windows is affected.

How to reproduce

  1. On Windows, build master with MinGW
  2. Run b-em with logical keyboard mapping
  3. Press any Key which needs Alt-Gr as its modifier (UK Keyboard ==> Pipe Symbol)
SteveFosdick commented 1 year ago

I'll have a look. The B-Em keyboard does not, as far as I know, track any other modifiers than Ctrl and Shift, i.e. the ones on the BBC micro keyboard. It also does not have any tables for different nationality of keyboards. What I think maybe going on here is that it is giving priority to the location of the key, i.e. where it would be be on a US/UK keyboard, rather than the unicode character the OS is providing.

egrath commented 1 year ago

As it works on Linux, i've digged a little bit into the issue by myself. It seems some strange behavior of the Allegro library. I've used a small Test application which just tracks keyboard input and it exposes the same behavior as b-em: Alt-Graph+Q is not recognized as the @-symbol in Windows, but only as 'q'.

Don't invest (currently) into this ticket, it's probably a issue upstream. Will keep the ticket here up-to-date as soon as new information regarding this surfaces.

Corresponding allegro.cc forum entry with test application: https://www.allegro.cc/forums/thread/618804/1053433

SteveFosdick commented 1 year ago

Thanks. I did do a little more checking of the debug messages in your original report and I notice that Allegro is providing the Unicode code for 'Q' (113) not '@'. It looks like you are actually trying to type the ASCII NUL character, i.e. ASCII code zero, hence holing down Alt-Gr to generate the '@' while also holding down Ctrl to get the BBC Micro to interpret the '@' key as a control character with |@ giving NUL.

What I think is happening is that Windows, or maybe Allegro, is also seeing the Ctrl modifier and that stops AltGr from selecting the tertiary level, hence the unicode 'Q' being given to B-Em.

egrath commented 1 year ago

https://github.com/liballeg/allegro5/issues/1430