I know how to detect key pressing. All keys except Control, Alt, Shift and CMD.
How can i detect when this keys are being pressed.
Thanks in advance.
If you want to detect these keys in something like a NSView
object, have a look at the NSResponder
class. When you overwrite a NSView
class (or one of its sublcasses), you can overwrite keyDown:(NSEvent *)theEvent
(Apple Documentation). When you call [theEvent modifierFlags]
, a NSUInteger
bitfield is returned, which you can then evaluate.
For instance, with
if ([theEvent modifierFlags] & NSCommandKeyMask) {
...
}
you can check if the Command key is pressed.
See Apple's Cocoa Event-handling Guide, especially the section "Handling Key Events" for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With