From: "Cody" Newsgroups: comp.os.msdos.djgpp Subject: [OT] Allegro keyboard handling Lines: 62 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Original-NNTP-Posting-Host: tel-ppp0116.ktsnet.com Message-ID: <3b11c6a7@leia.ktsnet.com> Date: Sun, 27 May 2001 22:23:00 -0500 NNTP-Posting-Host: 216.60.177.225 X-Complaints-To: abuse AT swbell DOT net X-Trace: nnrp1.sbc.net 991032906 216.60.177.225 (Mon, 28 May 2001 01:55:06 CDT) NNTP-Posting-Date: Mon, 28 May 2001 01:55:06 CDT Organization: SBC Internet Services To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com I need some severe help from anybody who has more sense than I do (which I'm sure is every single person who reads this). I have been trying to use Allegro's keyboard routines for a month now in order to detect multiple key presses, but I haven't succeeded yet. I need it for a small game that I'm making/experimenting with. What happens is this: if the user presses a key, it reads it just fine, until it presses another key with the original still held down. Here is when it completely ignores the first key and just reads the second key, or 3rd key, or whatever the case may be. How do I know when those others are still being pressed? I just don't understand this. It looks as if my code is practically the same as other examples from the net, and their code worked just perfectly. I have tested this on 2 different computers and 3 different keyboards to see if that was the problem, but I received the same result. Well, here is the code (I'll try to make as concise as possible)... btw, with the following code, at least when I pressed up and left at the EXACT same time it would return both up and left, but I want it to be where you hold up, it goes up; still hold up then hold left, it goes up left, not left... I also want to be able to detect a keypress besides the directions but w/ directions at same time, such as up, left, and the KEY_X key so that I can make, for instance, a character in my game fire his gun: #include "allegro.h" struct { int x,y,r,c; } mycircle; int main(int argc, char *argv[]) { allegro_init(); install_keyboard(); if (set_gfx_mode(GFX_SAFE, 320, 240, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set any graphic mode\n%s\n", allegro_error); return 1; } int a,b; mycircle.x=SCREEN_W/2; mycircle.y=SCREEN_H/2; mycircle.c=1; mycircle.r=5; while (!key[KEY_ESC]) { clear_keybuf(); /* same for me w/ or w/o this */ circlefill(screen,mycircle.x,mycircle.y,mycircle.r,mycircle.c); if (keypressed()) { if (key[KEY_LEFT]) --mycircle.x;/*move it left*/ if (key[KEY_RIGHT]) ++mycircle.x;/*move it right*/ if (key[KEY_UP]) --mycircle.y;/*move it up*/ if (key[KEY_DOWN]) ++mycircle.y;/*move it down*/ if (key[KEY_EQUALS])++mycircle.r;/*plus sign makes it bigger*/ if (key[KEY_MINUS]) --mycircle.r;/*minus sign... makes it smaller*/ if (key[KEY_ENTER]) ++mycircle.c;/*enter changes color*/ if (key[KEY_ESC]) break;/*exit from loop*/ } } readkey(); allegro_exit(); return 0; } END_OF_MAIN();