Every Shift Key Trap Regardless of OS X

I have a working code ( here ) that intercepts key codes for key change events without a modifier and events with a modified change.

But if you do this:

LSHIFT down -> RSHIFT down -> RSHIFT up -> LSHIFT up 

... internal 2 actions will not trigger any of these hooks, because the state of the modifier does not change!

(EDIT: Woops! I had to check this before writing, because virtually every modified modifier is created by every actual change.)

My only thought is perhaps to look further at an even lower level ( here ) - but it does not look beautiful no matter what angle I look at it from.

0
source share
1 answer

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".

+2
source

Source: https://habr.com/ru/post/987441/


All Articles