I’ve written a tool utilizing onKeyDown(key, repeat, flags, view)
which works fine on Windows, but not on OSX. After testing on a MacBook Air and a MacBook Pro, it seems I’ve been checking for the wrong key codes (for VK_MINUS and VK_EQUAL in particular) on OSX.
Most of the lists of OSX key codes I’ve found online (including the ones linked to from here) list VK_EQUAL and VK_MINUS as 0x18 and 0x1b respectively. I’m aware that keyboard layout may affect this, but this post seems to imply that it doesn’t (but maybe those keys in particular don’t change?). Should I be checking keyboard layout?
The key codes that I got were:
equal = 0x3d # expected 0x18
minus = 0x2d # expected 0x1b
What confused me even more is that when I was holding down modifier keys while I pressed them, the codes were different:
option + equal = 0x2260
shift + option + equal = 0xb1
option + minus = 0x2013
shift + option + minus = 0x2014
I don’t really how to properly handle this. Should I be bit twiddling? Should I be subtracting/adding a certain integer from them similar to this? Is it safe to assume that the key codes I got with modifier keys down are unique even with the modifier keys up? Also, is this changing of key codes normal behavior on OSX, or is this a SketchUp thing, or is it normal everywhere and I’ve only encountered it now?