Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Escape not being read straight off?

This thread is locked; no one can reply to it. rss feed Print
Escape not being read straight off?
HardTranceFan
Member #7,317
June 2006
avatar

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

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

Kikaru
Member #7,616
August 2006
avatar

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
Member #4,886
July 2004
avatar

Code?

Evert
Member #794
November 2000
avatar

Do you have something like sticky keys enabled?

HardTranceFan
Member #7,317
June 2006
avatar

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 }

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

TeamTerradactyl
Member #7,733
September 2006
avatar

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
Member #7,317
June 2006
avatar

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.

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

Evert
Member #794
November 2000
avatar

I said:

Do you have something like sticky keys enabled?

HardTranceFan
Member #7,317
June 2006
avatar

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

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

Arthur Kalliokoski
Second in Command
February 2005
avatar

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)

They all watch too much MSNBC... they get ideas.

HardTranceFan
Member #7,317
June 2006
avatar

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

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

TeamTerradactyl
Member #7,733
September 2006
avatar

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

Go to: