1

I need my Xamarin.App to run in background and show up it's window whenever globally available is pressed.

How can that be done with Xamarin.Mac?

brutallord
  • 861
  • 2
  • 11
  • 16
  • 1
    You are looking for `AddGlobalMonitorForEventsMatchingMask`, your app must also be OS trusted for accessibility: https://learn.microsoft.com/en-us/dotnet/api/appkit.nsevent.addglobalmonitorforeventsmatchingmask?view=xamarin-mac-sdk-14 https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/EventOverview/MonitoringEvents/MonitoringEvents.html#//apple_ref/doc/uid/10000060i-CH15-SW3 – SushiHangover Aug 12 '21 at 16:34
  • I've been playing around for a day, but still have no working solution. Things I've configured: - added my app to trusted apps for accessibility (in Security & Privacy) - allowed access to input monitoring (also in Security & Privacy) – brutallord Aug 26 '21 at 22:30
  • I've checked out: - global events monitor: responds to non-keyboard events, like mouse events. Perhaps, I need signed app (as per https://stackoverflow.com/questions/45986756/how-to-detect-keystrokes-globally-in-swift-on-macos/45994269#45994269), but it feels like long way (I'm not Apple Developer program member). - also checked out CGEvent API (same issue with access to keyboard events, as Tap is even not created with KeyDown mask) - tried to check out IO Kit (found API explanation at https://www.logcg.com/en/archives/2902.html), but it doesn't look like it has bindings in Xamarin.Mac. – brutallord Aug 26 '21 at 22:31
  • Help in greatly appreciated, as I'm failing to find reason, why events monitoring and CGEvent API are not allowing me to access global key strokes. And really hope, it is possible without signing app. – brutallord Aug 26 '21 at 22:31
  • @brutallord Does you found an efficent solution for that? There is any good answer on that problem. – Mondonno Oct 05 '21 at 13:30
  • Unfortunately, failed to make it work due to reasons mentioned above in a way I wanted (access to keybord presses from code). But, found a dirty, but working hack for my own - used iCanHazShortcut app, that handled key press and executed custom script - in my case, it touched specific file to notify app about keypress event. So this way the issue was solved. Although, have checked out sending Unix signals (SIGUSR1, particularly), but also experienced issues with making it work. – brutallord Oct 24 '21 at 00:11

0 Answers0