Example #1
0
        private void SetFilterState(bool state)
        {
            ManagedWrapper.SetFilter(_deviceContext, IsMonitoredDevice,
                                     state ? ManagedWrapper.Filter.All : ManagedWrapper.Filter.None);

            _filterState = state;
        }
Example #2
0
        public void Subscribe(int vid, int pid, dynamic callback)
        {
            _callback       = callback;
            _filteredDevice = HelperFunctions.GetDeviceId(_deviceContext, false, vid, pid, 1);
            if (_filteredDevice == 0)
            {
                throw new Exception($"Could not find device with VID {vid}, PID {pid}");
            }

            ManagedWrapper.SetFilter(_deviceContext, IsMonitoredDevice, ManagedWrapper.Filter.All);
            _timer = new MultimediaTimer()
            {
                Interval = 10
            };
            _timer.Elapsed += DoPoll;
            _timer.Start();
        }
Example #3
0
        private void PollThread()
        {
            ManagedWrapper.SetFilter(_deviceContext, IsMonitoredDevice, ManagedWrapper.Filter.All);
            int deviceId1;
            int deviceId2;
            var stroke1 = new ManagedWrapper.Stroke();
            var stroke2 = new ManagedWrapper.Stroke();

            while (true)
            {
                var strokes = new List <ManagedWrapper.Stroke>();
                if (ManagedWrapper.Receive(_deviceContext, deviceId1 = ManagedWrapper.WaitWithTimeout(_deviceContext, 10), ref stroke1, 1) > 0)
                {
                    strokes.Add(stroke1);
                    if (deviceId1 < 11)
                    {
                        if (ManagedWrapper.Receive(_deviceContext, deviceId2 = ManagedWrapper.WaitWithTimeout(_deviceContext, 0), ref stroke2, 1) > 0)
                        {
                            strokes.Add(stroke2);
                        }
                    }
                    if (!_block)
                    {
                        for (int i = 0; i < strokes.Count; i++)
                        {
                            var stroke = strokes[i];
                            ManagedWrapper.Send(_deviceContext, _deviceId, ref stroke, 1);
                        }
                    }
                    // Use array for callback, as the callback may be AHK code, and dealing with arrays in AHK is way simpler that Lists
                    var keyEvents = new KeyEvent[strokes.Count];
                    for (int i = 0; i < strokes.Count; i++)
                    {
                        var s = strokes[i];
                        keyEvents[i] = new KeyEvent {
                            Code = s.key.code, State = s.key.state
                        };
                    }
                    _callback(keyEvents);
                }
            }
        }