libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.53k stars 1.77k forks source link

macOS: spurious key events #10905

Open Devon7 opened 1 week ago

Devon7 commented 1 week ago

SDL2 mysteriously started reporting spurious keyboard events, then mysteriously went back to normal about 28 hours later.

    Real    SDL2    Seconds
    ====    ====    =======
    ↓RCTRL  ↓RCTRL  19.337
    ↓RALT   ↓RALT   24.903
        ↑RCTRL  24.905
        ↑RALT   24.905
    ↓X  ↓X  33.576
    ↑X  ↑X  33.619
    ↑RALT   ↓RCTRL  38.900
    ↑RCTRL  ↑RCTRL  44.117
↓ SDL_KEYDOWN
↑ SDL_KEYUP

    Peace
        --Devon

P.S. Nothing in MacOS changed prior to this lossage, except installing a new speech recognition language. No SDL apps were running when the syndrome began/ended. Multiple SDL apps were affected. No non-SDL apps were.

Devon7 commented 10 hours ago

This bug vanished for a few days until yesterday it reappeared after enabling Zoom keyboard shortcuts. The original occurrence was after changing a Dictation preference. Yesterday I could repeatedly and reliably enable/disable it by turning Zoom keyboard shortcuts on/off but now it is stuck in the buggy state.

dtime   NS time   SDL time   Event       Details
                             press left control key
        8401061.3            NSEvent 12  FlagsChanged flags=0x40101 keyCode=59
                             NSEvent 15  AppDefined
                  319593.655 SDL_KEYDOWN "Left Ctrl"   .c.. 0x40 LCTRL

                             press left option key
Δ=4.5   8401065.8            NSEvent 12  FlagsChanged flags=0xc0121 keyCode=58
Δ=0     8401065.8            NSEvent 12  FlagsChanged flags=      0 keyCode= 0
δ=4.490           319598.145 SDL_KEYDOWN "Left Ctrl"   .... 0x140 LCTRL REPEAT
δ=0               319598.145 SDL_KEYDOWN "Left Option" .... 0x100 LCTRL LALT
                             spurious SDL2 events
δ=0.033           319598.178 SDL_KEYUP   "Left Ctrl"   .... 0x100 LALT
δ=0               319598.178 SDL_KEYUP   "Left Option" ....   0x0 NONE

dtime is the time change, Δ=NS, δ=SDL NS time is NSEvent time = seconds SDL time is SDL_Event common.timestamp / 1000 = seconds Event and Details are logged by me, a Cocoa_PumpEventsUntilDate breakpoint and my SDL_WaitEventTimeout loop. NSEvent details are abbreviated, uncensored details follow. .c.. and .... indicate keystate[ SDLSCANCODE {LALT,LCTRL,RCTRL,RALT} ] decoded, followed by SDL_Event key.keysym.mod in hex and decoded, finally SDL_Event key.repeat decoded.

    Peace
        --Devon

P.S. Surprise, having taken time to investigate NextStep events in Cocoa_PumpEventsUntilDate, turning Zoom keyboard shortcuts on/off controls the bug again, effective the instant I click the checkbox.

P.P.S. My SDL_WaitEventTimeout (&event, 1) loop burns 20% CPU hoping to promptly log SDL events so they and my nonstop breakpoint po event print (int)event.type in Cocoa_PumpEventsUntilDate should output in temporal order.

NSEvent: type=FlagsChanged loc=(1066.7,1259.98) time=8401061.3 flags=0x40101 win=0x7fb78e449570 winNum=518911 ctxt=0x0 keyCode=59
NSEvent: type=AppDefined loc=(0,0) time=0.0 flags=0 win=0x7fb78e449570 winNum=518911 ctxt=0x0 subtype=0 data1=0 data2=0
NSEvent: type=FlagsChanged loc=(1066.7,1259.98) time=8401065.8 flags=0xc0121 win=0x7fb78e449570 winNum=518911 ctxt=0x0 keyCode=58
NSEvent: type=FlagsChanged loc=(1066.7,1259.98) time=8401065.8 flags=0 win=0x7fb78e449570 winNum=518911 ctxt=0x0 keyCode=0