Capture Modifier Key Press (Control, Alt, Shift o CMD)

I know how to detect a keystroke. All keys except Control, Alt, Shift and CMD.

How can I detect when these keys are pressed.

Thanks in advance.

+5
source share
2 answers

If you want to discover these keys in something like an object NSView, look at the class NSResponder. When you overwrite a class NSView(or one of its subclasses), you can overwrite keyDown:(NSEvent *)theEvent (Apple Documentation) . When you call [theEvent modifierFlags], a bit field is returned NSUInteger, which you can then evaluate.

For example, with

if ([theEvent modifierFlags] & NSCommandKeyMask) {
   ...
}
you can check if the Command key is pressed.

. Apple Cocoa , " ".

+5

- (void) flagsChanged: (NSEvent *)theEvent

[theEvent keyCode] CRTL, SHIFT, ALT .., , 0 .

OpenGL, :

-(BOOL) canBecomeKeyWindow
+3

All Articles