iDevGames Forums
2+ keys down? - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: 2+ keys down? (/thread-7023.html)

2+ keys down? - Fenris - Jun 11, 2003 08:14 AM

Hi all!

I was just wondering - how the heck do you do this? I use GetKeys for input into my Carbon-based application, and I just noticed that GetKeys only supports 2 (or was it three) keys down simultaneously. Sad I know that most of the games out there do support that, I thought I'd ask you how you do it. For instance, I need people to be able to jump and hold the jump button, push left to run left while mid-air, but now that means that I can't shoot! Bad. Smile

Any thoughts?

2+ keys down? - jSTIN - Jun 11, 2003 08:26 AM

In my carbon game I use this code to do keys.

if ( GetNextEvent(everyEvent, &event) )
            if(event.message == NULL)
            theKey = (event.message & keyCodeMask) >> 8;
            isDown = (event.what != keyUp);

On the GetNextEvent you might want to mask the events only to key events. To get modifier keys you need add something to it.

      if ( IsKeyDown(keyMap, keyCommand) )

This stuff works good for me.


2+ keys down? - NCarter - Jun 11, 2003 11:44 AM

GetKeys() supports as many keys simultaneously as your keyboard hardware. On recent keyboards you can often detect five or six non-modifier keys at once, but since certain keys block certain other keys you might have as few as two. Which keys affect which depends on the keyboard matrix layout.

Modifiers (command, option, shift, control and caps lock) aren't affected by this limitation, so they're good candidates for keys that you never want to fail (fire buttons, for example).

You could switch to an event based mechanism to try to avoid these problems, but I personally have never had any real trouble with GetKeys().