PDA

View Full Version : Carbon Key Events


Nickolei
2002.11.15, 06:47 PM
Now that Jaguar broke GetKeys for me I'm wondering if anyone has a good implementation of Carbon key events they'd like to share.

OneSadCookie
2002.11.15, 08:10 PM
What's broken about GetKeys?

And what precisely do you want by way of a "good implementation"?

Nickolei
2002.11.15, 09:16 PM
When I moved to Jaguar my GetKeys code doesn't get input.

The Fullscreen with AGL sample code part that uses GetKeys() doesn't work now.

Both these case are true most of the time...it has worked sparingly.

As far as a good implementation goes, I just wanted to see how somebody deals with Modifier keys and translating key events specifically for a game. My efforts haven't gone so well and I'm sure somebody has figured it out already.

Ian Kerr
2002.11.15, 09:44 PM
Let's say you want to check for Command + Q.

First check to see if the command key is down (0x37), and then check to see if the 'q' key is down (0x0C).

so...

if(IsKeyDown(0x37) && IsKeyDown(0x0C))
ExitToShell();

Then implement IsKeyDown() using GetKeys().

-- Ian

NCarter
2002.11.17, 05:22 AM
I guess that Nickolei is referring to something that I saw briefly after I first installed Jaguar. Basically, GetKeys() would just stop working at random. Logging out and in again would fix it temporarily, though.

I haven't seen this problem recur for a long time though, so I assume that it's something to do with some new Jaguar feature that I messed around with for a while and then stopped using. You're not using Inkwell, are you? That's the only thing I can think of....

Nickolei
2002.11.17, 11:23 AM
Nope not inkwell.

I recently updated to 10.2.2 but that may as well be coincidence.

So is the official stance is that GetKeys is naughty but not broken?

And nobody can point to an example of Carbon key Events done 'right'? Maybe I'll have to post something...

OneSadCookie
2002.11.17, 02:31 PM
To use Carbon events for key tracking:

Keep a global array of booleans. You probably need 128 of them, depending on what character codes are returned. Also keep an array of 5 booleans for the modifier keys.

Register for raw key down and raw key up events, and when you receive one of these, change the state of the appropriate element of your large array.

Register for modifier changed events, and when you receive one, set the state of all your modifier booleans.

Then in your game loop, just check whether a given element of one of the arrays is true to know whether that key is currently down.

It'll end up feeling like GetKeys()...

codemattic
2002.11.17, 05:37 PM
Originally posted by Nickolei
Now that Jaguar broke GetKeys for me

yup - when I upgraded to Jag most of my games stopped getting keyboard input. Rebooting fixed that for me - havent had it again since. Of course that doesnt help if someone d/ls your game and it doesnt work b/c they didnt know they had to reboot their machine after installing Jag the first time.