コード例 #1
0
        public override void DidFinishLaunching(NSNotification notification)
        {
            var isRetina        = NSScreen.MainScreen.BackingScaleFactor > 1.0;
            var isBigSurOrNewer = NSProcessInfo.ProcessInfo.IsOperatingSystemAtLeastVersion(new NSOperatingSystemVersion(11, 0, 0));

            string statusItemImageName = $"StatusBarImage{(isBigSurOrNewer ? "Template" : "")}{(isRetina ? "@2x" : "")}.png";

            _statusItem       = NSStatusBar.SystemStatusBar.CreateStatusItem(NSStatusItemLength.Variable);
            _statusItem.Image = new NSImage(statusItemImageName)
            {
                Template = isBigSurOrNewer
            };                                                                                               // defining as template will make the icon work in light/dark mode and reduced transparency (see #137)
            _statusItem.Target = this;
            _statusItem.Action = new ObjCRuntime.Selector("MenuAction");

            var container = TinyIoCContainer.Current;

            RegisterServices(container);
            UseRepositoryMonitor(container);

            _pop          = new NSPopover();
            _pop.Behavior = NSPopoverBehavior.Transient;
            _pop.Delegate = this;
            _pop.ContentViewController = new PopupViewController();

            _eventMonitor = NSEvent.AddGlobalMonitorForEventsMatchingMask(NSEventMask.KeyDown, HandleGlobalEventHandler);

            _updateTimer = new Timer(CheckForUpdatesAsync, null, 5000, Timeout.Infinite);

            _ipcServer = new IpcServer(new DefaultIpcEndpoint(), this);
            _ipcServer.Start();
        }
コード例 #2
0
        public override void DidFinishLaunching(NSNotification notification)
        {
            var    isRetina            = NSScreen.MainScreen.BackingScaleFactor > 1.0;
            string statusItemImageName = $"StatusBarImage{(isRetina ? "@2x" : "")}.png";

            _statusItem        = NSStatusBar.SystemStatusBar.CreateStatusItem(NSStatusItemLength.Variable);
            _statusItem.Image  = new NSImage(statusItemImageName);
            _statusItem.Target = this;
            _statusItem.Action = new ObjCRuntime.Selector("MenuAction");

            var container = TinyIoCContainer.Current;

            RegisterServices(container);
            UseRepositoryMonitor(container);

            _pop          = new NSPopover();
            _pop.Behavior = NSPopoverBehavior.Transient;
            _pop.Delegate = this;
            _pop.ContentViewController = new PopupViewController();

            _eventMonitor = NSEvent.AddGlobalMonitorForEventsMatchingMask(NSEventMask.KeyDown, HandleGlobalEventHandler);

            _updateTimer = new Timer(CheckForUpdatesAsync, null, 5000, Timeout.Infinite);

            _ipcServer = new IpcServer(new DefaultIpcEndpoint(), this);
            _ipcServer.Start();
        }
コード例 #3
0
 public void start()
 {
     for (int i = 0; i < mask.Length; i++)
     {
         monitor[i] = new Foundation.NSObject();
         monitor[i] = NSEvent.AddGlobalMonitorForEventsMatchingMask(mask[i], handler);
     }
 }
コード例 #4
0
        private void CaptureClicks()
        {
            NSEvent.AddGlobalMonitorForEventsMatchingMask(NSEventMask.LeftMouseDown, (NSEvent theEvent) =>
            {
                var windowNumber = theEvent.WindowNumber;

                var now = DateTime.UtcNow;

                Console.WriteLine(theEvent);

                using (var _context = new ClickContext())
                {
                    _context.Add(new Click
                    {
                        WindowOwnerName = GetWindow(windowNumber) ?? "unknown"
                    });
                    _context.SaveChanges();
                }
            });
        }
コード例 #5
0
        private void StartMonitoring()
        {
            globalEventMonitor = NSEvent.AddGlobalMonitorForEventsMatchingMask(
                NSEventMask.MouseMoved,
                (theEvent) => PrintMouseLocation("Global", theEvent.LocationInWindow));

            localEventMonitor = NSEvent.AddLocalMonitorForEventsMatchingMask(
                NSEventMask.MouseMoved,
                (theEvent) =>
            {
                CGPoint p;
                if (theEvent.Window != null)
                {
                    var rect = theEvent.Window.ConvertRectToScreen(new CGRect(theEvent.LocationInWindow, new CGSize(0, 0)));
                    p        = rect.Location;
                }
                else
                {
                    p = theEvent.LocationInWindow;
                }
                PrintMouseLocation("Local", p);
                return(theEvent);
            });
        }
コード例 #6
0
 /// <summary>
 /// Start monitoring events of a given mask
 /// </summary>
 public void Start()
 {
     monitor = NSEvent.AddGlobalMonitorForEventsMatchingMask(mask, handler) as NSObject;
 }