Taken from Justin Bu's answer here
I added another modifier in case someone stumbles upon this and wants other keys.
- (void) flagsChanged:(NSEvent*)theEvent{ if ([theEvent modifier] == 131330){ //do stuff regarding left shift }else if ([theEvent modifier] == 131332){ //do stuff regarding right shift }else if ([theEvent modifier] == 65792){ //caps lock is on }else if ([theEvent modifier] == 8388864){ //FN key pressed }else if ([theEvent modifier] == 262401){ //control key pressed }else if ([theEvent modifier] == 524576){ //option key pressed }else if ([theEvent modifier] == 1048840){ //command key pressed }else if ([theEvent modifier] == 256){ //there are no modified pressed and caps lock is off } }
I recommend storing some BOOL in your class, such as LShiftDown and RShiftDown , since this method should be called when modifiers are clicked. You can probably also detect this property in your keyDown implementation to detect differences such as "a" and "A".
source share