I am trying to detect system wide keyboard inputs for my mac application. To do so I am using the below code:
[NSEvent addGlobalMonitorForEventsMatchingMask:NSEventMaskKeyDown
handler:^(NSEvent *event) {
NSString *eventChars = [event characters];
unichar keyChar = [eventChars characterAtIndex:0];
NSLog(@"keyboard char is %c",keyChar);
}];
While this works perfectly and tracks keyboard input entered anywhere on Safari, the handler does not get triggered only if user tries to enter password in any web page (ex: password box in facebook login page, any login page with password box).While the username input can be tracked the password input cannot.
Is this the expected behaviour or am I missing something because this works perfectly with Chrome. All keyboard inputs can be tracked with the global monitor incase of Google Chrome.But fails only for this particular case in Safari.
Key events sent to
NSSecureTextField
(orNSSecureTextFieldCell
) are masked so that no event monitor can intercept or read them. This is a security feature to prevent applications from stealing passwords as they're typed, and there's no API to get around it.