Escape not being read straight off?
HardTranceFan

In my program, I use the left control key as my fire button, and the escape key to exit the game.

If I press the left control key, and then press escape, nothing happens. But if I press left control, then another key (in this case the space bar), and then escape, the game exits.

I've put a poll_keyboard() before the test for the escape key, in case that was needed, but no luck.

Is there any reason for the keyboard to behave in this manner? Why isn't an escape key press registered after I've pressed the left control key?

Jeroen

Kikaru

If you are using readkey(), it might change the scancodes or something. Really though, I can't help too much right now. It might make it easier if you showed us some of your code, though.

Jonatan Hedborg

Code?

Evert

Do you have something like sticky keys enabled?

HardTranceFan

the code that checks for the escape key is:

1while ((!key[KEY_ESC]) && (invaders.invadersLeft() != 0))
2 {
3 clear_to_color(buffer, 0);
4 
5 bullets.moveAll();
6 player.moveAndFire(&bullets, &invaders, xPlayer, yPlayer);
7 
8[cut out other drawing bits]
9 
10 player.draw(buffer);
11 
12 blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h);
13 poll_keyboard();
14 }

Jeroen

the code that checks the left control key is player.moveAndFire:

1void cPlayer::moveAndFire(cBullets *bulletList, cInvaders *invaderList, int &xPos, int &yPos)
2{
3 int xClosest, yClosest;
4
5 shield.move();
6 x += key[KEY_RIGHT] & x < 620;
7 x -= key[KEY_LEFT] & x > 20;
8 
9 if (key[KEY_LCONTROL] && fireDelay < clock())
10 {
11 fireDelay = clock() + (clock_t)(0.1*CLOCKS_PER_SEC);
12 bulletList->add(x, y - halfHeight, 0, -4, bullet_base);
13 }
14 invaderList->closest(xClosest, yClosest);
15 bulletList->setSpecial(x, y - halfHeight, xClosest, yClosest, key[KEY_SPACE]);
16 
17 xPos = x;
18 yPos = y - halfHeight;
19 }

TeamTerradactyl

How quickly in succession are you pressing your keys (Ctrl then Esc)? If you're using Windows, Ctrl+Esc is something that the OS looks at (I think it toggles something IIRC). If you're hitting Ctrl, then waiting a few seconds, then hitting ESC, I'm not really sure what that could be...

Could you try checking for both these keys simultaneously, and if so, give you a message or something that will tell you "A hotkey was pressed..." so you can see whether the OS/keyboard/whatever is actually "remembering" the Ctrl key for you?

-TT

HardTranceFan

It happens when I press down the control key once, or just hold it down. But I always release it and wait for a second or so before I try the escape key.

TeamTerradactyl: I'll try your suggestions, and, from what you've said, I have thought up a couple more tests I can try. I'm not too fussed by it as yet, but it is a curiosity and I was wondering if anyone else had experienced the problem.

Chances are I'm doing something naff in my code without realising it.

Evert
I said:

Do you have something like sticky keys enabled?

HardTranceFan

No, I turned sticky keys off soon after I first installed windows on my PC.

Arthur Kalliokoski

I've "turned sticky keys off" eight or nine times to no avail. It's broken. I like to use "shift" keys for "run" with the arrow keys and it keeps bringing up that stupid dialog box no matter what. (holding shift key down for 12 seconds or some such)

HardTranceFan

When I turned mine off the messagebox stopped popping up.

If a solution cannot be found, I'll just use another key for firing.

Jeroen

TeamTerradactyl

My only problem is having the Google Desktop search pop up anytime I hit Ctrl twice in a row :-)

IIRC, hit SHIFT five or so times until StickyKeys dialog opens. When it does, there should be both a checkbox and a button for each of those settings.

All 3 of my checkboxes are unchecked, but under each button, the top checkmark was checked, so the settings were still enabled. Uncheck the first checkboxes from each of those 3 buttons, and let us know if that turns it off for you...

-TT

Thread #588245. Printed from Allegro.cc