How do I know whether a certain key on the keyboard is pressed/down or unpressed/up on Mac? Right now I need it for the spacebar, but an answer that would work for any key would be perfect.
I don't want to detect the events:
-(void)keyDown:(NSEvent*)event;
-(void)keyUp:(NSEvent*)event;
I want the state of a key (spacebar) at a certain moment.
On Windows this seems possible (although I haven't tried it out) with the following code:
GetAsyncKeyState(VK_SPACE);
But I haven't found a solution for Mac yet.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…