示例#1
0
        public Interception(KeyboardFilterMode keyboardFilter, MouseFilterMode mouseFilter)
        {
            KeysHelper.CheckInterceptionKeysForDuplicates();
            this.KeyboardFilterMode = keyboardFilter;
            this.MouseFilterMode    = mouseFilter;
            if (MouseFilterMode == Enums.MouseFilterMode.None)
            {
                Interception.DisableMouseEvents = true;
            }

            this.hardwareId = new StringBuilder(Interception.HardwareIdSize);

            this.mouseWheelAutoOffDelay    = TimeSpan.FromMilliseconds(50);
            this.mouseMoveAutoOffDelay     = TimeSpan.FromMilliseconds(50);
            this.KeyPressDelay             = 1;
            this.ClickDelay                = 1;
            this.ScrollDelay               = 15;
            Interception.MouseMoveDeadZone = 1;

            // Initializing keyStates (false for every key on every device)
            this.keyStates = new Dictionary <string, Dictionary <InterceptionKey, bool> >();
            for (int i = 1; i <= Interception.MaxDeviceCount; i++)
            {
                string deviceStrongName;

                if (NativeMethods.IsKeyboard(i) > 0)
                {
                    deviceStrongName = new InterceptionKeyboard(Convert.ToUInt16(i), "dump").StrongName;
                }
                else
                {
                    deviceStrongName = new InterceptionMouse(Convert.ToUInt16(i), "dump").StrongName;
                }

                var states = new Dictionary <InterceptionKey, bool>();
                foreach (InterceptionKey key in Enum.GetValues(typeof(InterceptionKey)))
                {
                    states.Add(key, false);
                }

                this.keyStates.Add(deviceStrongName, states);
            }

            this.devices = new Dictionary <int, InterceptionDevice>();
        }
示例#2
0
        private Dictionary <int, InterceptionDevice> RescanInputDevices(Dictionary <int, InterceptionDevice> currentDeviceList)
        {
            var devices = new Dictionary <int, InterceptionDevice>();

            for (int id = 1; id < Interception.MaxDeviceCount; id++)
            {
                string hwid = this.GetHardwareID(id);
                if (hwid != null && !(NativeMethods.IsInvalid(id) > 0))
                {
                    bool isKeyboard = NativeMethods.IsKeyboard(id) > 0;
                    InterceptionDevice newDevice;

                    if (isKeyboard)
                    {
                        newDevice = new InterceptionKeyboard((uint)id, hwid);
                    }
                    else
                    {
                        newDevice = new InterceptionMouse((uint)id, hwid);
                    }

                    // Checking if we have this device in the current list
                    if (currentDeviceList.ContainsKey(id))
                    {
                        if (currentDeviceList[id].HasTheSamePropertiesAs(newDevice))
                        {
                            devices.Add(id, currentDeviceList[id]);
                            continue;
                        }
                    }

                    devices.Add(id, newDevice);
                }
            }

            return(devices);
        }