i need to know what key code of Command button in mac keyboard, do somebody know how to get it programmatically?
can i get the key code if user tap button Command + X (cut shortcut)? thank you for the suggestion
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m going to assume here that you’re dealing with NSEvents generated by the AppKit framework.
In NSEvent’s documentation, take a look at the
modifierFlagsmethod.And the flag you’re lookng for is specifically the
NSCommandKeyMask.Now, to get it, if you have a NSView view in focus… it inherits from NSResponder. One of the methods in NSResponder is
keyDown. So add akeyDownmethod to your subclassed view and the parameter it takes is aNSEvent. And that is how you would get your command button key.BTW & FYI, if you just want to get the command key by itself (which is what I suspect), that’s a bigger trick and I’m not sure if it’s possible with AppKit. Because the command key, like the control and shift keys, are modifier keys and that means when events get generated, NSEvent is expecting two keys to be pressed at the same time (e.g. Command + Q for Quit, Control + C for interrupt, Shift + A for capital A).