How to use Shift key to toggle a bool switch by parsing incoming NSEvents?

The InputMethodKit of macOS allows using NSEvents to parse key signals and handle them.
However, Shift key appears to have no keycode.

Is there a way to handle Shift key pressing signal to allow using it to toggle a bool switch?

1 Like

Shift and other modifier keys are stored in modifierFlags of NSEvent.

1 Like

Thanks for your response.
However, this only works for detecting whether Shift key is being "hold".
I want to detect a key release event.

Probably NSEvent.addLocalMonitorForEvents(matching:handler:) -- but this is really a question about apple frameworks rather than the Swift language and is better asked on the apple forums.

2 Likes