Exemple #1
0
        public SystemEvent(int eventId, Action callback)
        {
            EventId  = eventId;
            Callback = callback;

            _wndProcRegistration = WndProc.Listen(eventId, m => callback());
        }
Exemple #2
0
        public GlobalHotKey(int id, int virtualKey, int modifiers, Action callback)
        {
            Id         = id;
            VirtualKey = virtualKey;
            Modifiers  = modifiers;
            Callback   = callback;

            _wndProcRegistration = WndProc.Listen(786, m =>
            {
                // Filter out other hotkey events
                if (m.WParam.ToInt32() != Id)
                {
                    return;
                }

                // Throttling
                lock (_lock)
                {
                    if ((DateTimeOffset.Now - _lastTriggerTimestamp).Duration().TotalSeconds < 0.2)
                    {
                        return;
                    }

                    _lastTriggerTimestamp = DateTimeOffset.Now;
                }

                Callback();
            });
        }
        public PowerSettingNotification(IntPtr handle, Guid powerSettingId, Action callback)
        {
            Handle         = handle;
            PowerSettingId = powerSettingId;
            Callback       = callback;

            _wndProcRegistration = WndProc.Listen(536, m =>
            {
                // Filter out other power events
                if (m.GetLParam <PowerBroadcastSetting>().PowerSettingId != powerSettingId)
                {
                    return;
                }

                Callback();
            });
        }