Esempio n. 1
0
        /// <summary>
        /// Simulate KeyDown events of passed key code list.
        /// </summary>
        /// <param name="keyCodes">List of key codes to simulate event</param>
        public void SimulateKeyDown(KeyCommand keyCommand)
        {
            if (keyCommand == null)
            {
                return;
            }

            var keyCodes = keyCommand.KeyCodes;

            if (keyCodes == null)
            {
                return;
            }

            foreach (var keyCode in keyCodes)
            {
                // Register command
                if (!KeyDownCommandRegistry.ContainsKey(keyCode))
                {
                    KeyDownCommandRegistry.Add(keyCode, new List <KeyCommand>());
                }

                var list = KeyDownCommandRegistry[keyCode];
                list.Add(keyCommand);
                StartPolling();

                Debug.WriteLine(string.Format("KEY DOWN {0}", keyCode));
                InputSimulatorInstance.Keyboard.KeyDown(keyCode);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Simulate KeyUp events of passed key code list.
        /// Note that the list is processed in reverse order.
        /// </summary>
        /// <param name="keyCodes">List of key codes to simulate event</param>
        public void SimulateKeyUp(KeyCommand keyCommand)
        {
            if (keyCommand == null)
            {
                return;
            }

            var keyCodes = keyCommand.KeyCodes;

            if (keyCodes == null)
            {
                return;
            }

            for (var i = keyCodes.Count; --i >= 0;)
            {
                var keyCode = keyCodes[i];
                Debug.WriteLine(string.Format("KEY UP {0}", keyCode));
                SimulateKeyUp(keyCode);

                // Unregister Command
                if (KeyDownCommandRegistry.ContainsKey(keyCode))
                {
                    var keyCommands = KeyDownCommandRegistry[keyCode];
                    keyCommands.Remove(keyCommand);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Simulate KeyPress events of passed key code list.
        /// </summary>
        /// <param name="keyCodes">List of key codes to simulate event</param>
        public void SimulateKeyPress(KeyCommand keyCommand)
        {
            if (keyCommand == null)
            {
                return;
            }

            var keyCodes = keyCommand.KeyCodes;

            if (keyCodes == null)
            {
                return;
            }

            var modifierKeyCodes = keyCodes.Intersect(ModifierKeyCodes);
            var normalKeyCodes   = keyCodes.Except(modifierKeyCodes);

            Debug.WriteLine(string.Format("KEY PRESS {0}", string.Join("+", keyCodes)));
            InputSimulatorInstance.Keyboard.ModifiedKeyStroke(modifierKeyCodes, normalKeyCodes);
        }