[squeak-dev] Unix keyboard events lose track when multiple keys pressed or keys held down

tim Rowledge tim at rowledge.org
Sat Jan 16 01:13:58 UTC 2021



> On 2021-01-15, at 2:20 PM, David T. Lewis <lewis at mail.msen.com> wrote:
> 
> 
> Tim, can you try this on your Raspberry Pi and see if you can reproduce?

Yeah, I've done various test including what Marcel suggested and it Just Don't Work Here.

Marcel's idea provides - 
[350.0 at 397.0 keyDown (97) 67898453]
[350.0 at 397.0 keystroke 'a' (97) 67898453]a
[350.0 at 397.0 keyDown (97) 67898523]
[350.0 at 397.0 keystroke 'a' (97) 67898523]a
[350.0 at 397.0 keyDown (97) 67898609]
[350.0 at 397.0 keystroke 'a' (97) 67898609]a
[350.0 at 397.0 keyDown (98) 67898697]
[350.0 at 397.0 keystroke 'b' (98) 67898697]b
[350.0 at 397.0 keyUp (98) 67898779]

I also tried logging the KeyboardEvent>>#setType:buttons:position:keyValue:hand:stamp: to catch the rawest level in the image that I could get to, the KeyboardStateWatcher>>#handleListenEvent: to see if my keyboard listener was triggering (it is) and turned on DEBUG_EVENT& DEBUG_CONV in the VM to log what the VM sees.

Oh, and I have the rather cute KeyboardEventMorphs deployed - they are nice little widgets that you can set to listen to specific key events and display the state.


In my terminal I get this - 

(handleEvent)X KeyPress      state 0x0 raw keycode 38
keycode 38
x2sqKey XLookupBoth count 1
x2sqKey == 97
symbolic, keyCode, ucs4: 61, 97, 61
pressed, buffer: 0, 0
multi_key reset
keyCode, ucs4, multi_key_buffer: 97, 97, 0
signalInputEvent
EVENT (recordKeyboardEvent): time: 68294181 key down  `a' (97 = 0x61) ucs4 97
signalInputEvent
EVENT (recordKeyboardEvent): time: 68294181 key char  `a' (97 = 0x61) ucs4 97
(ioGetNextEvent) KEYBOARD evt: time: 68294181 char: 97 utf32: 0 
(ioGetNextEvent) KEYBOARD evt: time: 68294181 char: 97 utf32: 97 
(ioGetNextEvent) KEYBOARD evt: time: 68294181 char: 97 utf32: 97 
rawkeyUp: 97 <<<<<---------the rawkey*: & key*: lines are from the image logging
keyup: 65
rawkeyDown: 97
keydown: 65
rawkeystroke: 97
keystroke: 65

(handleEvent)X KeyRelease    state 0x0 raw keycode 38
signalInputEvent
EVENT (recordKeyboardEvent): time: 68294264 key up    `a' (97 = 0x61) ucs4 0

(handleEvent)X KeyPress      state 0x0 raw keycode 38
keycode 38
x2sqKey XLookupBoth count 1
x2sqKey == 97
symbolic, keyCode, ucs4: 61, 97, 61
pressed, buffer: 0, 0
multi_key reset
keyCode, ucs4, multi_key_buffer: 97, 97, 0
signalInputEvent
EVENT (recordKeyboardEvent): time: 68294264 key down  `a' (97 = 0x61) ucs4 97
signalInputEvent
EVENT (recordKeyboardEvent): time: 68294264 key char  `a' (97 = 0x61) ucs4 97
(ioGetNextEvent) KEYBOARD evt: time: 68294264 char: 97 utf32: 0 
(ioGetNextEvent) KEYBOARD evt: time: 68294264 char: 97 utf32: 97 
(ioGetNextEvent) KEYBOARD evt: time: 68294264 char: 97 utf32: 97 
rawkeyUp: 97
keyup: 65
rawkeyDown: 97
keydown: 65
rawkeystroke: 97
keystroke: 65

(handleEvent)X KeyPress      state 0x0 raw keycode 56
keycode 56
x2sqKey XLookupBoth count 1
x2sqKey == 98
symbolic, keyCode, ucs4: 62, 98, 62
pressed, buffer: 0, 0
multi_key reset
keyCode, ucs4, multi_key_buffer: 98, 98, 0
signalInputEvent
EVENT (recordKeyboardEvent): time: 68294327 key down  `b' (98 = 0x62) ucs4 98
signalInputEvent
EVENT (recordKeyboardEvent): time: 68294327 key char  `b' (98 = 0x62) ucs4 98
(ioGetNextEvent) KEYBOARD evt: time: 68294327 char: 98 utf32: 98 
(ioGetNextEvent) KEYBOARD evt: time: 68294327 char: 98 utf32: 98 
rawkeyDown: 98
keydown: 66
rawkeystroke: 98
keystroke: 66

(handleEvent)X KeyRelease    state 0x0 raw keycode 56
signalInputEvent
EVENT (recordKeyboardEvent): time: 68294767 key up    `b' (98 = 0x62) ucs4 0
(ioGetNextEvent) KEYBOARD evt: time: 68294767 char: 98 utf32: 0 
rawkeyUp: 98
keyup: 66

(handleEvent)X KeyRelease    state 0x0 raw keycode 38

Note how there is no signalInputEvent triggered by that last KeyRelease?

> 
> Here is the Spur VM that I used:

Mine is built last night from sources of a few days ago.

/home/pi/Documents/Squeak/sqcogspurlinuxhtRPi/lib/squeak/5.0-202012301853/squeak
Open Smalltalk Cog[Spur] VM [CoInterpreterPrimitives VMMaker.oscog-eem.2908]
Unix built on Jan 14 2021 21:19:52 Compiler: 8.3.0
platform sources revision VM: 202012301853 tim at Diziet.local:Documents/Squeak/opensmalltalk-vm Date: Wed Dec 30 10:53:48 2020 CommitHash: 85708ef49 Plugins: 202012301853 tim at Diziet.local:Documents/Squeak/opensmalltalk-vm
CoInterpreter VMMaker.oscog-eem.2908 uuid: fddf1a4f-c585-45ab-8a74-442230cd3dbd Jan 14 2021
StackToRegisterMappingCogit VMMaker.oscog-eem.2905 uuid: b2778a08-d45d-4f84-8467-21a8eccf46dc Jan 14 2021

So my VM is ~six months newer than yours. Wonder if something got broken since then... or maybe another one of those 'amusing' compiler errors.

Looking at the sqUnixX11.c on github it appears that lines ~3746 are the place where we need to concentrate.
    case KeyRelease:
      noteEventState(evt->xkey);
      {
	KeySym symbolic;
	int keyCode, ucs4;
	if (XPending(stDisplay))
	  {
	    XEvent evt2;
	    XPeekEvent(stDisplay, &evt2);
	    if ((evt2.type == KeyPress) && (evt2.xkey.keycode == evt->xkey.keycode) && ((evt2.xkey.time - evt->xkey.time < 2)))
	      break;
	  }
	keyCode= x2sqKey(&evt->xkey, &symbolic);
	ucs4= xkeysym2ucs4(symbolic);
	if ((keyCode >= 0) || (ucs4 > 0))
	  recordKeyboardEvent(keyCode, EventKeyUp, modifierState, ucs4);
      }
      break;
If something makes that last clause skip then we wouldn't call recordKeyboardEvent() and so wouldn't... record... the keyboard event. That in turn would mean no signalInputEvent(). Similarly, that XPending(stDisplay) test can cause us to skip.

Oh well, add more debugging clutter to the VM...


tim
--
tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
Watch out for off-by-one errorss.




More information about the Squeak-dev mailing list