Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

I'm interested in the reason why it needs to be tagged iPhone/iPad — surely you can do all the conversion in OS X? Also, the iPhone/iPad "keyboard" is fundamentally a text input method (see UITextInput) —it's not that it "won't supply keycodes"; there simply aren't any (and what keycode/modifiers should it supply when you tap "A", hold for a bit, and pick a random accented version?).

If you're going to do this, test it on a variety of (odd) input methods on both the iPad and OS X. If there's an API to insert a string, do so (but this might not work so well for games which read scan codes...). You could even write a custom input method extension which accepted Unicode strings.

It's debatable what should happen when a Dvorak VNC client types to a QWERTY VNC server...


I'll end with a tangential story:

A little over a year ago (before I got an iPhone), I got a N810. If anything, it makes a half-decent SSH/VNC client and has a decent keyboard.

Except it's not a standard keyboard. 1 is Fn-Q and ! is Fn-A, but when I type Fn-A to get "!", the VNC server ends up typing "1". Typing Shift-Fn-A gives me the "!" I was looking for (I think Shift-Fn-Q also works).

Something, somewhere, parses the character "!", decides that it has the same scan code as "1", and types the scan code for 1 with no modifier. It could automatically hold down Shift. It might even be able to insert a string. Instead, it just fails.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top