Carbon Key Events

Member
Posts: 33
Joined: 2002.04
Post: #1
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
What's broken about GetKeys?

And what precisely do you want by way of a "good implementation"?
Quote this message in a reply
Member
Posts: 33
Joined: 2002.04
Post: #3
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.
Quote this message in a reply
Member
Posts: 49
Joined: 2002.05
Post: #4
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
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #5
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....

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Member
Posts: 33
Joined: 2002.04
Post: #6
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...
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #7
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()...
Quote this message in a reply
Member
Posts: 304
Joined: 2002.04
Post: #8
Quote: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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  [For David, aarku] Carbon Events OneSadCookie 4 5,674 Mar 5, 2013 10:20 PM
Last Post: SethWillits
  Carbon events in windowed/full screen mode. Help needed. Anton Petrov 1 3,761 Dec 18, 2008 05:35 AM
Last Post: DoG
  Simulating "system idle" events in Carbon applications ascotti 4 3,668 May 2, 2006 03:22 PM
Last Post: OneSadCookie
  Carbon Keyboard Events IBethune 7 5,960 Oct 22, 2002 05:58 AM
Last Post: IBethune
  Carbon events (again) sealfin 2 3,819 Jul 1, 2002 06:34 AM
Last Post: sealfin