views:

31

answers:

2

Is there a way to convert a unicode character to a Mac virtual keycode? (without building my own table?) It looks like on Windows there is VkKeyScanEx, but I'm not aware of a similar function for Cocoa on OS X.

I'm actually trying to do this for the iPad. I want to convert character taken from the keyboard and convert them into key codes, since the iPad keyboard won't supply keycodes.

A: 

The ShortcutRecorder project on GoogleCode has an NSValueTransformer subclass for converting strings to keycodes and vice versa, but I'm not sure if it'll work on iOS. It's a great place to start looking, though.

Dave DeLong
I'm assuming this is for a VNC-alike, which means it's possible (if the protocol supports it, and if it doesn't, it should) to send the character to the OS X app and do the conversion in OS X.
tc.
A: 
tc.
Thank you for the comments. I understand the risks presented by all kinds of different keyboards, but all I wanted to know if such a function exists. As it turns out, I wrote my own. It's not perfect, but for a standard English keyboard, it works fine, and support for other keyboards can be added.
Silromen
And presumably, if you have an external keyboard attached to your iPad, it would be reasonable to expect keycodes, yet there aren't any, and so it just makes certain kinds of applications harder to do.
Silromen
The job of an operating system is to abstract away from hardware. The abstraction Apple's chosen for the iPad is "text input", not "keypresses"; the keypress abstraction simply doesn't work well for many input methods. Yes, they could add some sort of keycode; similarly, Flash could offer raw mouse input (to get subpixel accuracy/turn off mouse acceleration/blah), but the demand just isn't there. If Apple added USB/Bluetooth mouse support, they'd show something on screen, but you wouldn't get anything except touch events.
tc.