From: "Eric Botcazou" Newsgroups: comp.os.msdos.djgpp Subject: Re: [OT] Allegro keyboard handling Date: Mon, 28 May 2001 13:49:53 +0200 Lines: 38 Message-ID: <9ete0q$e1m$1@news2.isdnet.net> References: <3b11c6a7 AT leia DOT ktsnet DOT com> NNTP-Posting-Host: dyn-213-36-133-215.ppp.libertysurf.fr X-Trace: news2.isdnet.net 991050586 14390 213.36.133.215 (28 May 2001 11:49:46 GMT) X-Complaints-To: abuse AT isdnet DOT net NNTP-Posting-Date: 28 May 2001 11:49:46 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2014.211 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com > if (keypressed()) { > if (key[KEY_LEFT]) --mycircle.x;/*move it left*/ > ... > if (key[KEY_ESC]) break;/*exit from loop*/ > } The problem lies in this loop that begins with keypressed(). keypressed() returns TRUE if keypresses are waiting in the buffer and it can of course detect autorepeat. But: autorepeat works with the *last* pressed key only. That is, when the first key is being held down, Allegro generates autorepeat for it hence keypressed() return TRUE and it works. Now, if you press another key then release it, Allegro doesn't generate autorepeat for the first key any longer, because it is not the last pressed key, and keypressed() return FALSE. The solution is to get rid of keypressed(): while (!key[KEY_ESC]) { if (circle_has_moved) circlefill(screen,mycircle.x,mycircle.y,mycircle.r,mycircle.c); 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*/ } As a general rule, try to avoid mixing buffered key input (keypressed(), readkey(), clear_keybuf) and the key[] array in a loop. -- Eric Botcazou ebotcazou AT multimania DOT com