iDevGames Forums
Keyboard Handling - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Keyboard Handling (/thread-8245.html)



Keyboard Handling - skyhawk - Oct 25, 2010 02:29 PM

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.


RE: Keyboard Handling - Skorche - Oct 25, 2010 02:40 PM

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.


RE: Keyboard Handling - skyhawk - Oct 25, 2010 02:41 PM

(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.


RE: Keyboard Handling - OneSadCookie - Oct 25, 2010 02:42 PM

Something like http://github.com/OneSadCookie/ObjCGameBase/blob/master/Classes/GBKeyCodes.m


RE: Keyboard Handling - skyhawk - Oct 25, 2010 02:58 PM

(Oct 25, 2010 02:42 PM)OneSadCookie Wrote:  Something like http://github.com/OneSadCookie/ObjCGameBase/blob/master/Classes/GBKeyCodes.m

yes, something like that Ninja

Will try it out when I get home tonight.


RE: Keyboard Handling - Skorche - Oct 25, 2010 07:51 PM

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.


RE: Keyboard Handling - skyhawk - Oct 25, 2010 10:36 PM

(Oct 25, 2010 02:42 PM)OneSadCookie Wrote:  Something like http://github.com/OneSadCookie/ObjCGameBase/blob/master/Classes/GBKeyCodes.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!


RE: Keyboard Handling - OneSadCookie - Oct 25, 2010 11:37 PM

Fork me and send a pull request so others can benefit Wink


RE: Keyboard Handling - AnotherJake - Oct 26, 2010 12:00 AM

dude, I'm going to pretend I didn't just read that.


RE: Keyboard Handling - OneSadCookie - Oct 26, 2010 08:29 AM

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/ObjCGameBase/blob/master/Classes/GBGLView.m for how I handle this.


RE: Keyboard Handling - skyhawk - Oct 26, 2010 08:47 AM

(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/ObjCGameBase/blob/master/Classes/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