|
keypressed |
clovekx
Member #3,479
April 2003
|
I'd like to stop the program while there is a key pressed. This freezes the program: do{ rest(1); poll_keyboard(); }while(keypressed()); And this doesnt wait for the key to be released: do{ clear_keybuf(); rest(1); poll_keyboard(); }while(keypressed());
EDIT:
Is there some better way to do so? --- |
CursedTyrant
Member #7,080
April 2006
|
int main() { while (!keypressed()) { } return 0; } Or... int main() { bool Running = true; while (Running) { if (keypressed()) { Running = false; } } return 0; }
--------- |
clovekx
Member #3,479
April 2003
|
The problem with your code is that it waits for a key to be pressed, but I want to wait for all keys to be released. Just adding '!' will not work. --- |
Evert
Member #794
November 2000
|
Don't call poll_keyboard(); it's not nescessary. |
clovekx
Member #3,479
April 2003
|
Wouldn't it be useful to add some key[KEY_ANY] to allegro, that will be set if any key is pressed? --- |
Krzysztof Kluczek
Member #4,191
January 2004
|
Quote: Wouldn't it be useful to add some key[KEY_ANY] to allegro, that will be set if any key is pressed? I don't think it's necessary you can easily check entire array yourself. do { int i; for(i=0;i<KEY_MAX;i++) if(key<i>) break; } while(i<KEY_MAX); Also "KEY_ANY" should be probably reserved for "Any" key that might be added in future keyboards. ________ |
CGamesPlay
Member #2,559
July 2002
|
Maybe al_keydown that does what Krzysztof just did? -- Ryan Patterson - <http://cgamesplay.com/> |
clovekx
Member #3,479
April 2003
|
Quote: Also "KEY_ANY" should be probably reserved for "Any" key that might be added in future keyboards. And what if there will be some "Max" key in the future? --- |
BAF
Member #2,981
December 2002
|
Seems to me like setting KEY_ANY would be more optimal than scanning the entire array each time you want to know. |
Thomas Harte
Member #33
April 2000
|
Future versions of Allegro have, if the plan hasn't quietly changed, the option of event based input. So if you're laying your code out like that you'd just do a loop like: while(!KeyDown) { al_WaitForEvent(&ev); switch(ev.Type) { case AL_KEYDOWN: KeyDown = true; break; /* check for other important stuff, like a quit message */ } }
[My site] [Tetrominoes] |
Evert
Member #794
November 2000
|
Quote: Future versions of Allegro have, if the plan hasn't quietly changed, the option of event based input. Ithink that already works in 4.3 |
|