VOGONS


First post, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie

Sometimes, when I use DOSBox, the program running inside it acts as if one of the shift keys had been held down - sometimes the Ctrl key, sometimes, the Shift key. I usually have to exit DOSBox and relaunch to clear this out.

If it is possible to create a command that would clear all the shift states, so that I could attach it to a key and try to correct this problem without exiting, would anyone be generous enough to show me what the code would be?

Many thanks for any help with this.

Reply 1 of 8, by Qbix

User metadata
Rank DOSBox Author
Rank
DOSBox Author

take a look at the alt-tab handling in sdlmain.cpp
It contains the info you need

Water flows down the stream
How to ask questions the smart way!

Reply 2 of 8, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie
Qbix wrote:

take a look at the alt-tab handling in sdlmain.cpp
It contains the info you need

case SDL_KEYDOWN:
case SDL_KEYUP:
// ignore event alt+tab
if (event.key.keysym.sym==SDLK_LALT) sdl.laltstate = event.key.type;
if (event.key.keysym.sym==SDLK_RALT) sdl.raltstate = event.key.type;
if (((event.key.keysym.sym==SDLK_TAB)) &&
((sdl.laltstate==SDL_KEYDOWN) || (sdl.raltstate==SDL_KEYDOWN))) break;

Thank you! I think you're telling me that I can adapt this so that if SDL_KEYDOWN is true, I should generate an event that acts as if the key is now up, but that may be the stupidest possible interpretation.

I may almost be able to figure out how to code this myself, and I suppose I should do the same with SDLK_LCTRL, SDLK_LSHIFT, etc.

Thank you again - but if anyone can provide any further pointers on how to do this, I'd be very grateful.

Reply 4 of 8, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie
Qbix wrote:

Maybe Add the release codes to the keyboard buffer.

Presumably like this:

/* Now poke a "release ALT" command into the keyboard buffer
* we have to do this, otherwise ALT will 'stick' and cause
* problems with the app running in the DOSBox.
*/
KEYBOARD_AddKey(KBD_leftalt, false);
KEYBOARD_AddKey(KBD_rightalt, false);

That really does tell me almost everything I need to know, I think. Thank you again!

But don't underestimate my ignorance. I'll probably be back for more help before I'm done, unfortunately.

Reply 5 of 8, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie

I'm not at the machine I build on, so I won't be able to test this until later, but I wonder if this looks more or less like what I should be doing. It's for sdl_mapper.cpp:

static void ClearShiftStates(bool pressed) {
if (!pressed)
return;
KEYBOARD_AddKey(KBD_leftalt, false);
KEYBOARD_AddKey(KBD_rightalt, false);
KEYBOARD_AddKey(KBD_leftctrl, false);
KEYBOARD_AddKey(KBD_rightctrl, false);
KEYBOARD_AddKey(KBD_leftshift, false);
KEYBOARD_AddKey(KBD_rightshift, false);
// KEYBOARD_AddKey(KBD_capslock, false); // EDIT - this shouldn't be here
}

and, near the foot of the file:

	MAPPER_AddHandler(&ClearShiftStates,MK_f6,MMOD1|MMOD2,"unshift","Clear Shifts");

Apologies for time-wasting if this is merely foolish and ignorant.

Last edited by emendelson on 2013-08-02, 21:52. Edited 1 time in total.

Reply 6 of 8, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie

EDIT: Well, I built this with the line that cleared CapsLock, and that had the unfortunate effect of turning CapsLock ON when it was already off. So I'm going to try again without the line about CapsLock and will report back if it works correctly when shift states seemed to be locked.

I edited this message because, at first, I reported that the patch worked perfectly, but that was before I realized that I shouldn't have included capslock in the code. Meanwhile, thank you for showing me how to do this!