예제 #1
0
        public void HandleKeyEvent(Key key, KeyPressDirection pressDirection)
        {
            lock (sendingKeys)
            {
                sendingKeys.Add(key);
            }

            if (key.KeyCode == Keys.Packet)
                 throw new Exception("Cannot send packet.");
            switch (key.KeyType)
            {
                case KeyType.Character:
                    SendInput.Send(key.Character, pressDirection);
                    break;
                case KeyType.KeyCode:
                    SendInput.Send(key.KeyCode, pressDirection);
                    break;
                default:
                    throw new Exception();
            }

            lock (sendingKeys)
            {
                sendingKeys.Remove(key);
            }
        }
예제 #2
0
파일: SendInput.cs 프로젝트: hediet/Neo2Net
        public static void Send(Keys keyCode, KeyPressDirection pressDirection)
        {
            //var flags = (KeyboardFlag)0;
            var flags = IsExtendedKey(keyCode) ? KeyboardFlag.ExtendedKey : 0;

            if (pressDirection == KeyPressDirection.Up)
                flags |= KeyboardFlag.KeyUp;

            Send((UInt16)keyCode, (ushort)KeysHelper.ConvertToScanCode(keyCode), (UInt32)flags);
        }
예제 #3
0
파일: SendInput.cs 프로젝트: hediet/Neo2Net
        public static void Send(char character, KeyPressDirection pressDirection)
        {
            UInt16 scanCode = character;

            var flags = KeyboardFlag.Unicode;

            if (pressDirection == KeyPressDirection.Up)
                flags |= KeyboardFlag.KeyUp;

            // Handle extended keys:
            // If the scan code is preceded by a prefix byte that has the value 0xE0 (224),
            // we need to include the KEYEVENTF_EXTENDEDKEY flag in the Flags property.
            if ((scanCode & 0xFF00) == 0xE000)
                flags |= KeyboardFlag.ExtendedKey;

            Send(0, scanCode, (UInt32)flags);
        }
예제 #4
0
 public void HandleKeyEvent(Key key, KeyPressDirection pressDirection)
 {
     byte status = 0;
     if (pressDirection == KeyPressDirection.Down)
         status |= 1;
     if (key.KeyType == KeyType.Character)
     {
         status |= 2;
         writer.Write(status);
         writer.Write(key.Character);
     }
     else
     {
         writer.Write(status);
         writer.Write((Int32)key.KeyCode);
     }
 }
예제 #5
0
        public void HandleKeyEvent(SemanticKey semanticKey, KeyPressDirection pressDirection)
        {
            var firstPressEvent = !pressedKeys.Remove(semanticKey);

            if (pressDirection == KeyPressDirection.Down)
                pressedKeys.Add(semanticKey);

            pressedKeys2 = pressedKeys.ToArray();

            var lshiftKey = new SemanticKey("ShiftL", null);
            var rshiftKey = new SemanticKey("ShiftR", null);

            if (semanticKey.Name == "MouseLeftClick")
            {
                var m = new WindowsMouse();
                if (pressDirection == KeyPressDirection.Down)
                    m.SetButtonState(MouseButton.Left, KeyPressDirection.Down);
                else
                    m.SetButtonState(MouseButton.Left, KeyPressDirection.Up);
                return;
            }

            KeyDefinition kd;
            if (semanticKey.Name != null && keyDefinitions.TryGetValue(semanticKey.Name, out kd))
            {
                var isShiftPressed = pressedKeys.Contains(lshiftKey) || pressedKeys.Contains(rshiftKey);
                var modifierMatch = true;
                if (kd.Modifiers != null)
                {
                    var set1 = new HashSet<QwertzModifier>(kd.Modifiers);
                    var set2 = new HashSet<QwertzModifier>();
                    if (isShiftPressed)
                        set2.Add(QwertzModifier.Shift);
                    modifierMatch = set1.SetEquals(set2);
                }

                if (kd.QwertzVirtualKeyCode != null && modifierMatch)
                    targetKeyboard.HandleKeyEvent(new Key((Keys)kd.QwertzVirtualKeyCode), pressDirection);
                else if (kd.Text != null)
                    targetKeyboard.HandleKeyEvent(new Key(kd.Text.First()), pressDirection);
            }
            else if (semanticKey.Text != null)
                targetKeyboard.HandleKeyEvent(new Key(semanticKey.Text.First()), pressDirection);
        }
예제 #6
0
        public void SetButtonState(MouseButton button, KeyPressDirection direction)
        {
            var flag = MouseEventTFlags.LEFTDOWN;
            if (direction == KeyPressDirection.Down)
            {
                if (button == MouseButton.Left)
                    flag = MouseEventTFlags.LEFTDOWN;
                else if (button == MouseButton.Middle)
                    flag = MouseEventTFlags.MIDDLEDOWN;
                else if (button == MouseButton.Right)
                    flag = MouseEventTFlags.RIGHTDOWN;
            }
            else if (direction == KeyPressDirection.Up)
            {
                if (button == MouseButton.Left)
                    flag = MouseEventTFlags.LEFTUP;
                else if (button == MouseButton.Middle)
                    flag = MouseEventTFlags.MIDDLEUP;
                else if (button == MouseButton.Right)
                    flag = MouseEventTFlags.RIGHTUP;
            }

            mouse_event((uint)flag, 0, 0, 0, UIntPtr.Zero);
        }
예제 #7
0
 public void HandleKeyEvent(Key key, KeyPressDirection pressDirection)
 {
     Console.WriteLine(pressDirection + " " + key + " scancode: " + KeysHelper.ConvertToScanCode(key.KeyCode));
 }
예제 #8
0
 public void HandleKeyEvent(Key key, KeyPressDirection pressDirection)
 {
 }
예제 #9
0
 public void HandleKeyEvent(SemanticKey key, KeyPressDirection pressDirection)
 {
     Console.WriteLine(pressDirection + " " + key);
 }