From: "Graeme Fenwick" Newsgroups: comp.os.msdos.djgpp Subject: Allegro keypressed() always returning False Date: Thu, 17 Dec 1998 12:39:04 -0000 Lines: 94 X-Newsreader: Microsoft Outlook Express 4.72.2106.4 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 NNTP-Posting-Host: ppp47-92.dial.nildram.co.uk Message-ID: <3678fb52.0@mercury.nildram.co.uk> X-Trace: 17 Dec 1998 12:38:42 GMT, ppp47-92.dial.nildram.co.uk To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Hi all! I'm having problems with Allegro's keypressed() function. It seems to be returning false, regardless of what the user types in. Leaving it out means the rest of the routine (based around readkey()) works, but then it pauses every time it needs to scan the keyboard- not brilliant!. (As a workaround, I suppose I could scan each key individually- not very elegant though.) I get the impression the answer would be quite simple- *if* the problem was caused either by stupidity on my part, or something that isn't obvious from the docs. Searching the FAQ and Usenet didn't turn up much either, so it might just be a really lousy error on my part ;-) Anyway.. here's the program fragment. It's a bit long, but you can ignore the switch, and all the #defines... /* Example program only. Alt-Ctrl-End exits. */ #include #include #define NO_KEY 0 #define ONE 1 #define NONVALID 2 #define UP 3 #define DOWN 4 #define LEFT 5 #define RIGHT 6 #define PLUS 7 #define ENTER 8 #define SAVE 9 int detect_key(void); int main(void) { allegro_init(); install_keyboard(); while(1) printf("%d \n", detect_key()); return 0; } /********** DETECT_KEY: Custom routine only detects relevant keys. Some keys have aliases (e.g. numpad '+' matches '=') */ int detect_key(void) { unsigned int key; if (!keypressed()); return NO_KEY; /******** PROBLEM HERE!! *** buffer empty? */ key = (unsigned) readkey() >> 8; switch (key) { /* note alias keys- also, no breaks needed */ case KEY_UP: case KEY_8: return UP; case KEY_DOWN: case KEY_2: return DOWN; case KEY_LEFT: case KEY_4: return LEFT; case KEY_RIGHT: case KEY_6: return RIGHT; case KEY_PLUS_PAD: case KEY_EQUALS: return PLUS; case KEY_1: return ONE; case KEY_ENTER: return ENTER; case KEY_S: case KEY_SLASH: return SAVE; default: return NONVALID; /* nonvalid key pressed */ } } -- ============================================ Graeme Fenwick | gfenwick AT BYESPAMprimex DOT co DOT uk "Please remove BYESPAM filter when replying by mail" -- WILLIAM SHAKESPEARE, Hamlet.