Path: utzoo!mnetor!uunet!husc6!bbn!rochester!ur-tut!dpvc From: dpvc@ur-tut.UUCP (Davide P. Cervone) Newsgroups: comp.sys.amiga Subject: Re: Repeating multiple keys Message-ID: <685@ur-tut.UUCP> Date: 11 Dec 87 17:56:50 GMT References: <209@dalcsug.UUCP> <1213@sugar.UUCP> Reply-To: dpvc@tut.cc.rochester.edu.UUCP (Davide P. Cervone) Organization: Univ. of Rochester Computing Center Lines: 45 Keywords: How do I detect this? Key Status In article <1213@sugar.UUCP> peter@sugar.UUCP (Peter da Silva) writes: >In article <209@dalcsug.UUCP>, peter@dalcsug.UUCP (Peter Philip) writes: >> Can anyone tell me where I could find an example of detecting which keys >> are being held down? ... > >Open a window with IDCMP flags set to include RAWKEY. > >When you get a key message... > > while(msg = GetMsg(win->UserPort)) > switch(msg->Class) { > case RAWKEY: > key_down[msg->Code & 0x7F] = > (msg->Code & 0x80)?0:1; > break; > } > >-- Peter da Silva `-_-' ...!hoptoad!academ!uhnix1!sugar!peter >-- Disclaimer: These U aren't mere opinions... these are *values*. One caution about using this method in a multi-window, multi-tasking environment: you may miss some key presses or key-up events. For instance, suppose I'm holding down the RETURN key (or any other key), and then click in another window, then let go of the key, then click in the original window again. The original window will not see the RETURN-key-up event, and will think I'm still holding it down. This becomes more serious if you are using this method to track things like SHIFT keys (don't do this, use the Qualifier field instead). This may not be important in your application, but maybe it is. Just though I'd point out where the problem could come in. Perhaps what we need is an input handler that keeps track of the keyboard status (I'm pretty big on input handlers, you might have noticed). This would avoid the problem stated above, because if you put the handler before intuition, you will get ALL the key events no mater which window they are destined for. A really slick implementation would set up a message port so that as many tasks as what to know could ask it for the current keyboard state. It could return some sort of array where each bit represented a key. The details are left to the interested reader... Davide P. Cervone dpvc@tut.cc.rochester.edu dpvc@ur-tut.UUCP DPVC@UORDBV.BITNET