I'm looking to read the state of the keyboard in Cocoa (for a game I'm building in SpriteKit).
NSResponder will certainly give me key presses, but I don't get events for modifier presses, and if I hold down a single key, and then press another key, I stop getting keyDown events for the first.
In ancient times (on my MacPlus), I used GetKeys()
to fetch the keyboard state at the top of each frame.
I'm surprised and baffled that this still seems to work:
KeyMap keys;
GetKeys(keys);
UInt32 keys3 = CFSwapIn32BigToHost(keys[3].bigEndianValue);
if (keys3 & 4)
{
NSLog(@"F1 is down");
}
However, I'm certain that there must be issues with localization, different keyboards, or something (using a 30-year old toolbox call gives me pause).
Is there a modern equivalent to this function?