2+ keys down?

Posts: 834
Joined: 2002.09
Post: #1
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?
Quote this message in a reply
Posts: 50
Joined: 2002.12
Post: #2
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.

Quote this message in a reply
Posts: 365
Joined: 2002.04
Post: #3
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().

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Spaces on Snow Leopard and ctrl/arrow keys GolfHacker 19 24,256 Dec 4, 2012 03:18 PM
Last Post: bmantzey
  Multiple Keys down in SDL silver9172 2 6,859 May 30, 2009 06:16 PM
Last Post: scgames
  [NSEvent keyCode] to actual keys? teknein 8 14,958 Sep 5, 2007 07:27 AM
Last Post: teknein
  Keys ......again Coin 7 8,280 Jan 29, 2005 09:38 PM
Last Post: belthaczar
  Keys I Can Use In Games Nick 10 7,401 Jul 22, 2004 11:49 PM
Last Post: AnotherJake