Keyboard Handling

Moderator
Posts: 916
Joined: 2002.10
Post: #1
So I've run into an interesting issue. I've recently updated my game from using just KeyUp KeyDown to accepting the whole range of keys on my keyboard via keycodes.

This so far has worked our GREAT (minus a small bug dealing with flagsChanged not returning opposite events, but that's an easy fix). HOWEVER, I've run into an issue where keycodes have no earthly mapping to what's on the keyboard in any form. "wasd" on my qwerty keyboard is ",aoe" on my friend's keyboard. So how does one properly store keycode and still display the correct thing to the user.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #2
Woo Dvorak!

Old Carbon based games seemed to always interpret keys as being in QWERTY, but as a non-QWERTY user I don't think you should do it. You really need to make the keys configurable.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #3
(Oct 25, 2010 02:40 PM)Skorche Wrote:  Woo Dvorak!

Old Carbon based games seemed to always interpret keys as being in QWERTY, but as a non-QWERTY user I don't think you should do it. You really need to make the keys configurable.

I was thinking of leaving you guys out! but the stickler in me won't let me.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #5
(Oct 25, 2010 02:42 PM)OneSadCookie Wrote:  Something like http://github.com/OneSadCookie/ObjCGameB...KeyCodes.m

yes, something like that Ninja

Will try it out when I get home tonight.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #6
Honestly, I wouldn't feel bad about being "left out". It's generally easier to switch the keyboard layout before playing a game than to reconfigure keys so I'm quite used to it. Wink It's the games that require typing/chatting AND don't allow the keys to be reconfigured that are killer.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #7
(Oct 25, 2010 02:42 PM)OneSadCookie Wrote:  Something like http://github.com/OneSadCookie/ObjCGameB...KeyCodes.m

This seemed to mostly work except:
Caplocks showed up as Key #57
NumLock/Clear showed up as Key #71
Some other key on my keyboard that I don't know what it was showed up as another strange Key #098
No distinction between 1-0 and keypad 1-0,

For CapLock:
According to the function UCKeyTranslate returned with err equal to noErr, however "actualStringLength" was equal to 0, but the buffer had this in it:
[0] 19320
[1] 37395
[2] 0
misc...

my temp fix for this was just adding those keys to the fallback table. Though I'm concerned about spacebar showing up as blank instead of "Space". Just hacked that so that keycode 49 always returns "Space"


So.....
so far so good, time to test on dvorak!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
Fork me and send a pull request so others can benefit Wink
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #9
dude, I'm going to pretend I didn't just read that.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #10
Quote:Skyhawk asked out-of-band

a) how to fork me

http://help.github.com/ covers everything you need in a few simple steps.

Github is really great. Git is pretty neat too. Well worth learning how to use both. Essentially all open development worth a damn is happening on Github these days, and participation is vastly easier than SourceForge.

Quote:b) whether there's a way to get modifier key changes via keyUp: and keyDown:

No, but flagsChanged: has a keyCode. See http://github.com/OneSadCookie/ObjCGameB...GBGLView.m for how I handle this.
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #11
(Oct 26, 2010 08:29 AM)OneSadCookie Wrote:  
Quote:b) whether there's a way to get modifier key changes via keyUp: and keyDown:

No, but flagsChanged: has a keyCode. See http://github.com/OneSadCookie/ObjCGameB...GBGLView.m for how I handle this.
yeah, I figured that much out, but your code handles it better than mine, so I switched Sneaky
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  keyboard limitations daveh84 8 4,334 Feb 13, 2009 02:48 PM
Last Post: ferum
  Event Handling (Keyboard and Mouse) bwalters 6 7,346 Mar 12, 2006 08:17 PM
Last Post: OneSadCookie
  Cocoa Keyboard help Iceman 5 4,032 Aug 1, 2005 06:06 PM
Last Post: nabobnick
  CB Key handling skyhawk 6 3,538 Aug 12, 2003 10:13 AM
Last Post: kelvin
  Keyboard Question rogue 6 3,633 Jul 10, 2003 06:36 AM
Last Post: rogue