We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 92

Summary: Keyboard Events and Shift
Product: SDL Reporter: Sam Lantinga <slouken>
Component: eventsAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED WORKSFORME QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: wtb.mike
Version: don't know   
Hardware: x86   
OS: Windows (All)   

Description Sam Lantinga 2006-01-27 02:19:37 UTC
Date: Tue, 18 May 2004 17:25:53 -0500
From: "David White" <davidnwhite@optusnet.com.au>
Subject: [SDL] Keyboard Events and Shift

It seems to me that when keyboard events arrive in the SDL_KeyboardEvent structure, the keysym that arrives is based on the state of the 'shift' key at the time the event is processed, rather than the time the event happens.

In Battle for Wesnoth, which is implemented in a single thread, we have a situation where a textbox is on-screen to send messages to other players at the same time as the AI is processing. This means that sometimes a keyboard event might not be processed promptly if the AI is processing. When the keyboard event finally is processed, the user might have let go of the shift key, and a letter that was meant to be capitalized is not capitalized.

As far as I can work out from reports from users, this bug seems to be Windows-specific, as it apparently does not occur on Linux (I don't have access to a Linux machine to test on though).

Does anyone know of a way that I can get this to work, without having to use threads?

David White
Lead Developer
Battle for Wesnoth (http://www.wesnoth.org)
Comment 1 Ryan C. Gordon 2006-01-27 11:23:27 UTC
Setting Sam as "QA Contact" on all bugs (even resolved ones) so he'll definitely be in the loop to any further discussion here about SDL.

--ryan.

Comment 2 Sam Lantinga 2006-03-14 02:33:06 UTC
SDL calls GetKeyboardState(), which is I believe is current with the keyboard state as processed in Windows messages.  This should work correctly for the windib driver, but it's possible that the keyboard state is out of sync on the windx5 driver (since all windows messages are processed before keyboard input is processed)

Can you confirm that the bug does not occur with the windib video driver?
Comment 3 Sam Lantinga 2006-06-21 04:11:23 UTC
Moving this to fixed for 1.2.10.  Please reopen it if it's still active using the windib driver, or if we switch back to the directx driver by default.
Comment 4 Mike 2007-05-29 00:33:20 UTC
(In reply to comment #3)
> Moving this to fixed for 1.2.10.  Please reopen it if it's still active using
> the windib driver, or if we switch back to the directx driver by default.

I'm currently using libSDL 1.2.10 and the SHIFT key event detection seems to be working perfectly for everything (that I've tried) *except* for Windows 98.  So Win2000/WinXP, MacOS, various Linux distros seem to be fine.

Is it possible I'm doing something wrong or is there something about Win98 that's special.  I've set SDL_VIDEODRIVER=windib.  Is that all that's necessary to override the use of the DX driver?

THanks for the help!
Comment 5 Sam Lantinga 2007-07-05 23:07:47 UTC
I tried to reproduce this using checkkeys.exe on Windows 98 and it appears to work correctly.  Is there a test case that I can run to check this out?
Comment 6 James Bellinger 2008-01-26 11:33:16 UTC
Hmm. I get this exact bug too. We use the DirectX driver, though. Is that now unsupported?
Comment 7 Mike 2008-01-30 09:13:29 UTC
Sorry Sam, I missed your update a few months ago and unfortunately don't have my Win98 snapshot running at the moment, so I'm unable to create a testcase for you.  If I run into this problem again, I will try checkkeys.exe and create a testcase.

James, if you're getting this same problem while using DX, perhaps it's not an SDL problem, but rather a Win98 keyboard problem...

m.