addGlobalMonitorForEventsMatchingMask handler not

2019-08-17 02:42发布

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.

1条回答
男人必须洒脱
2楼-- · 2019-08-17 03:11

Key events sent to NSSecureTextField (or NSSecureTextFieldCell) 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.

查看更多
登录 后发表回答