MBS Hotkeys / CarbonHotKeyMBS question

Is there a way to let keyspresses go through on the original application they’re coming from?

My menubar app shows different information when a keyboard letter or number is pressed in Clip Studio Paint. While my app is displaying the right information when a key is pressed, Clip Studio Paint no longer registers those keystrokes, so it doesn’t change tools.

Sounds more like you need NSEventMonitorMBS class to install a global monitor to get copies of keys pressed.

I tried that earlier to respond to this, but it looks like it no longer captures keyboard events globally even with accessibility permission granted.

Likely a hardening measure by Apple, but maybe I was just missing something since I didn’t spend that much time on it.

Unfortunately, I think Jared is right. Neither the Mouse Click & Keyboard Events example nor Event Logging example catch keyclicks from another app when the other app is frontmost.

I also tried using a timer that checked Keyboard.AsyncKeyDown - it only catches modifier keys & arrow keys when another app is in front.

I’ve settled on using only two shortcuts that iterates up and down through a list of tool dictionaries to display the info I want. It’s a PITA compared to catching keyboard keys, but it’s a least clunky solution.

Oh yes, there are requirements to be come a trusted app to be allowed to receive these.
Like entitlements, info.plist entries and being a signed app.

Not sure what is the current requirement.

1 Like

I think you need to add a globalmonitor in the MBS-Sample:

call Window1.AppEventMonitor.addLocalMonitorForEventsMatchingMask(NSEventMBS.NSAnyEventMask)

call Window1.AppEventMonitor.addGlobalMonitorForEventsMatchingMask(NSEventMBS.NSAnyEventMask)

Then the app need to be code-signed and in Privacy Settings you need to grant access to Accessibility features. Then the MBS-Sample worked in my test (cool!)

best, Thomas

1 Like

I’ve code-signed it with App Wrapper using a Development profile, and added it to Accessibility and Input Monitoring in Privacy and Security, and I’m not getting any keystrokes when I switch to another app, unfortunately.

Do you handle the global event of NSEventMonitorMBS-object? I forgot to mention this. May send your modified sample if you like.

After some fumbling about with the Global Event - I got it working! Thanks so much!