Esempio n. 1
0
 private void OnInputDeviceConnectionChanged(InterceptionDevice newDevice, bool isRemoved)
 {
     if (this.InputDeviceConnectionChanged != null)
     {
         this.InputDeviceConnectionChanged(this, new InterceptionDeviceEventArgs(newDevice, isRemoved));
     }
 }
Esempio n. 2
0
        public InterceptionDeviceEventArgs(InterceptionDevice device, bool isRemoved)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            this.Device    = device;
            this.IsRemoved = isRemoved;
        }
        public virtual bool HasTheSamePropertiesAs(InterceptionDevice deviceToCompare)
        {
            var props = deviceToCompare.GetType().GetProperties();

            foreach (var property in props)
            {
                var v1 = property.GetValue(this, null);
                var v2 = property.GetValue(deviceToCompare, null);
                if (!v1.Equals(v2))
                {
                    return(false);
                }
            }

            return(true);
        }
        internal InterceptionEventArgs(InterceptionDevice device, List <KeyInfo> keyInfos, bool handled = false)
            : base()
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            if (keyInfos == null)
            {
                throw new ArgumentNullException("keyInfos");
            }

            this.Device   = device;
            this.KeyInfos = keyInfos;
            this.Handled  = handled;
        }
Esempio n. 5
0
        private void ReleaseKeyWithDelay(InterceptionDevice device, InterceptionKey key, TimeSpan delay)
        {
            var action = new Action(() =>
            {
                if (this.IsKeyDown(device, key))
                {
                    this.keyStates[device.StrongName][key] = false;
                    if (this.InputActivity != null)
                    {
                        this.InputActivity(this, new InterceptionEventArgs(device, new List <KeyInfo>()
                        {
                            new KeyInfo(key, false)
                        }));
                    }
                }
            });

            var task = new DelayedTask(action, delay);

            task.Run();
        }
Esempio n. 6
0
        private void DriverCallback()
        {
            NativeMethods.SetFilter(this.context, NativeMethods.IsKeyboard, (int)this.KeyboardFilterMode);
            NativeMethods.SetFilter(this.context, NativeMethods.IsMouse, (int)MouseFilterMode);

            Stroke stroke = new Stroke();

            while (NativeMethods.Receive(this.context, this.deviceId = NativeMethods.Wait(this.context), ref stroke, 1) > 0)
            {
                bool isKeyboard = NativeMethods.IsKeyboard(this.deviceId) > 0;

                if (!isKeyboard)
                {
                    if (Interception.DisableMouseEvents)
                    {
                        if (!Interception.SwallowMouse)
                        {
                            this.Send(this.context, this.deviceId, ref stroke, 1);
                        }

                        continue;
                    }
                }

                // Checking if the input device is already in the device list. If not - adding it.
                if (this.devices.ContainsKey(this.deviceId))
                {
                    this.currentDevice = this.devices[this.deviceId];
                }
                else
                {
                    continue;
                }

                // Getting the keys
                if (isKeyboard)
                {
                    this.currentKeys = this.GetKeyboardKeys(stroke.Key);
                }
                else
                {
                    this.currentKeys = this.GetMouseKeys(stroke.Mouse);
                }

                // Saving the key states
                foreach (var keyInfo in this.currentKeys)
                {
                    this.keyStates[this.currentDevice.StrongName][keyInfo.Key] = keyInfo.IsDown;
                }

                if (!isKeyboard && stroke.Mouse.Rolling != 0)
                {
                    foreach (var keyInfo in this.currentKeys)
                    {
                        if (KeysHelper.IsMouseWheelKey(keyInfo.Key))
                        {
                            this.ReleaseKeyWithDelay(this.currentDevice, keyInfo.Key, this.mouseWheelAutoOffDelay);
                        }
                    }
                }

                // Raising the event, which determines whether the input will be blocked or not.
                if (this.InputActivity != null)
                {
                    var args = new InterceptionEventArgs(this.currentDevice, this.currentKeys);
                    this.InputActivity(this, args);
                    if (args.Handled)
                    {
                        continue;
                    }
                }

                this.Send(this.context, this.deviceId, ref stroke, 1);
            }

            this.Unload();

            throw new Exception(
                      "Interception.Receive() failed for an unknown reason. The driver has been unloaded.");
        }
Esempio n. 7
0
 public bool IsKeyDown(InterceptionDevice device, InterceptionKey key)
 {
     return(this.keyStates[device.StrongName][key]);
 }