Ejemplo n.º 1
0
        /// <summary> Maps key input to events </summary>
        RlEvent handleVKey(VKey key, VInput input)
        {
            var entity = this.controller.actor;
            var dir    = entity.get <Body>().facing;

            switch (key)
            {
            case VKey.Select:
                return(PlayerCommands.onSelectKeyPressed(entity, this.gameCtx));

            case VKey.Cancel:
                // this.cradle.push(new MenuControl(this.god, new InvMenu(this.god, this.context.controlled.get<Inventory>())));
                break;

            case VKey.Ground:
                break;

            case VKey.RestATurn:
                break;

            default:
                break;
            }

            return(null);
        }
Ejemplo n.º 2
0
        public static bool SendInput(VKey key)
        {
            Press(key);
            Release(key);

            return(true);
        }
Ejemplo n.º 3
0
        public void KeyDown(VKey key, List <VKey> pressedKeys)
        {
            if (_configurationModel.Enable == DisplayOption.Counters || _configurationModel.Enable == DisplayOption.Both)
            {
                Shortcut shortcut = ResolveShortcut(key, pressedKeys, new List <Shortcut>()
                {
                    _configurationModel.CounterShortcuts.Next,
                    _configurationModel.CounterShortcuts.Previous,
                    _configurationModel.CounterShortcuts.Increment,
                    _configurationModel.CounterShortcuts.Decrement,
                    _configurationModel.CounterShortcuts.Reset
                });
                if (shortcut != null && shortcut.Command.CanExecute(null))
                {
                    shortcut.Command.Execute(null);
                }
            }

            if (_configurationModel.Enable == DisplayOption.Sounds || _configurationModel.Enable == DisplayOption.Both)
            {
                Shortcut shortcut = ResolveShortcut(key, pressedKeys, new List <Shortcut>()
                {
                    _configurationModel.SoundShortcuts.Pause,
                    _configurationModel.SoundShortcuts.Continue,
                    _configurationModel.SoundShortcuts.Stop
                });
                if (shortcut != null && shortcut.Command.CanExecute(null))
                {
                    shortcut.Command.Execute(null);
                }
            }
        }
Ejemplo n.º 4
0
 private void Key_Up(VKey key)
 {
     KeyUp?.Invoke(key, pressedKeys);
     if (pressedKeys.Contains(key))
     {
         pressedKeys.Remove(key);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Simulate a key being pressed down and immediately released.
        /// </summary>
        /// <param name="vKey">Virtual key to simulate.</param>
        /// <param name="modifiers">Key modifiers in effect.</param>
        public static void KeyPress(VKey vKey, byte modifiers)
        {
            bool alt   = Win32.CheckMask(modifiers, (byte)KeyModifiers.Alt);
            bool ctrl  = Win32.CheckMask(modifiers, (byte)KeyModifiers.Ctrl);
            bool shift = Win32.CheckMask(modifiers, (byte)KeyModifiers.Shift);

            KeyPress(vKey, alt, ctrl, shift, false);
        }
Ejemplo n.º 6
0
 public static bool SendKeyDown(IntPtr hWnd, VKey vkey, bool sys = false)
 {
     return(Native.SendMessage(
                hWnd,
                (int)(sys ? Message.SYSKEY_DOWN : Message.KEY_DOWN),
                (uint)vkey, Native.GetLParam(1, vkey, 0, (byte)(sys ? 1 : 0), 0, 0)
                ) == 0);
 }
Ejemplo n.º 7
0
 public static bool PostKeyUp(IntPtr hWnd, VKey vkey, bool sys = false)
 {
     return(Native.PostMessage(
                hWnd,
                (int)(sys ? Message.SYSKEY_UP : Message.KEY_UP),
                (uint)vkey, Native.GetLParam(1, vkey, 0, (byte)(sys ? 1 : 0), 1, 1)
                ));
 }
Ejemplo n.º 8
0
 private void Key_Down(VKey key)
 {
     if (!pressedKeys.Contains(key))
     {
         pressedKeys.Add(key);
         KeyPress?.Invoke(key, pressedKeys);
     }
     KeyDown?.Invoke(key, pressedKeys);
 }
Ejemplo n.º 9
0
        public void InstertVKey(VKey vkey, string id)
        {
            if (_vkeyRepo.ContainsKey(id))
            {
                throw new System.Exception("The key " + id + " already exists.");
            }

            vkey.id = _vkeyRepo.Count;
            _vkeyRepo.Add(id, vkey);
        }
Ejemplo n.º 10
0
        public void UpdateVKey(VKey vkey, string id)
        {
            if (!_vkeyRepo.ContainsKey(id))
            {
                throw new NoSuchKeyException();
            }

            vkey.name     = id;
            _vkeyRepo[id] = vkey;
        }
Ejemplo n.º 11
0
 public bool isDown(VKey key)
 {
     if (key == VKey.AxisKey)
     {
         return(this.vDir.isDown);
     }
     else
     {
         return(this.isKeyDown(key));
     }
 }
Ejemplo n.º 12
0
 public bool isPressed(VKey key)
 {
     if (key == VKey.AxisKey)
     {
         return(this.vDir.isPressed);
     }
     else
     {
         return(this.isKeyPressed(key));
     }
 }
Ejemplo n.º 13
0
        /// <summary> Consumes a specific key and returns whether it was pressed or not. </summary>
        public bool consume(VKey key)
        {
            if (key == VKey.AxisKey)
            {
                return(this.consumeDir());
            }
            var  bt     = this._buttons[key];
            bool result = bt.isPressed;

            this._buttons[key].consumePulseBuffer();
            return(result);
        }
Ejemplo n.º 14
0
        public static void KeyboardEvent(VKey keycode, bool downpress)
        {
            byte key = (byte)keycode;

            if (downpress)
            {
                keybd_event(key, 0, 0, 0);
            }
            else
            {
                keybd_event(key, 0, KEYEVENTF_KEYUP, 0);
            }
        }
Ejemplo n.º 15
0
        public void KeyUp(VKey key, List <VKey> pressedKeys)
        {
            if (_applicationStateModel.ModifiedBindable != null)
            {
                _applicationStateModel.ModifiedBindable.Keys.Clear();
                foreach (VKey pressedKey in pressedKeys)
                {
                    _applicationStateModel.ModifiedBindable.Keys.Add(pressedKey);
                }

                _applicationStateModel.BindKeysOpened   = false;
                _applicationStateModel.ModifiedBindable = null;
            }
        }
Ejemplo n.º 16
0
        public void KeyDown(VKey key, List <VKey> pressedKeys)
        {
            Shortcut shortcut = ResolveShortcut(key, pressedKeys, new List <Shortcut>()
            {
                _configurationModel.SoundShortcuts.Pause,
                _configurationModel.SoundShortcuts.Continue,
                _configurationModel.SoundShortcuts.Stop
            });

            if (shortcut != null && shortcut.Command.CanExecute(null))
            {
                shortcut.Command.Execute(null);
            }
        }
Ejemplo n.º 17
0
        public static uint GetLParam(Int16 repeatCount, VKey vkey, byte extended, byte contextCode,
                                     byte previousState,
                                     byte transitionState)
        {
            var  lParam   = (uint)repeatCount;
            uint scanCode = GetScanCode(vkey);

            lParam += scanCode * 0x10000;
            lParam += (uint)(extended * 0x1000000);
            lParam += (uint)(contextCode * 2 * 0x10000000);
            lParam += (uint)(previousState * 4 * 0x10000000);
            lParam += (uint)(transitionState * 8 * 0x10000000);

            return(lParam);
        }
Ejemplo n.º 18
0
        public static bool PostKeyPress(IntPtr hWnd, VKey vkey, bool sys = false, int delay = 10)
        {
            if (!PostKeyDown(hWnd, vkey, sys))
            {
                return(false);
            }

            //Send VM_CHAR
            //if (PostMessage(hWnd, (int)Message.VM_CHAR, (uint)key, GetLParam(1, key, 0, 0, 0, 0)))
            //  return false;

            Thread.Sleep(delay);

            return(PostKeyUp(hWnd, vkey, sys));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Simulate a key being released.
        /// </summary>
        /// <param name="vKey">Virtual key to simulate.</param>
        public static void KeyUp(VKey vKey)
        {
            bool isExtended = IsExtendedKey(vKey);

            uint scanCode = MapVirtualKey((uint)vKey, 0);

            if (isExtended)
            {
                keybd_event((byte)vKey, (byte)scanCode, (uint)KeyEvents.KeyUp | (uint)KeyEvents.ExtendedKey, IntPtr.Zero);
            }
            else
            {
                keybd_event((byte)vKey, (byte)scanCode, (uint)KeyEvents.KeyUp, IntPtr.Zero);
            }
        }
Ejemplo n.º 20
0
        public static VKey GetVirtualKey(char c, out ShiftState shift)
        {
            shift = ShiftState.NONE;
            short result = VkKeyScanEx(c, loadedKeyboard);

            if (result == -1)
            {
                return(VKey.UNDEFINED);
            }

            VKey key = (VKey)(result & 0xFF);

            shift = (ShiftState)(result >> 8);

            return(key);
        }
Ejemplo n.º 21
0
        public FormMacroAction(MacroAction action)
        {
            InitializeComponent();

            Array vkeys = Enum.GetValues(typeof(VKey));

            for (int i = 0; i < vkeys.Length; i++)
            {
                VKey key = (VKey)vkeys.GetValue(i);

                cbxKeys.Items.Add(new VKeyItem(key));
                if (key == VKey.F1)
                {
                    cbxKeys.SelectedIndex = i;
                }
            }

            if (action == null)
            {
                chbKey.Checked = true;
            }
            else
            {
                if (action.Delay.HasValue)
                {
                    chbDelay.Checked = true;

                    nudMinutes.Value     = (int)action.Delay.Value.Minutes;
                    nudSeconds.Value     = (int)action.Delay.Value.Seconds;
                    nudMiliseconds.Value = (int)action.Delay.Value.Milliseconds;
                }
                else
                {
                    chbKey.Checked = true;

                    cbxKeys.SelectedIndex = 0;
                    for (int i = 0; i < vkeys.Length; i++)
                    {
                        VKey key = (VKey)vkeys.GetValue(i);
                        if (key == action.Key.Value)
                        {
                            cbxKeys.SelectedIndex = i;
                        }
                    }
                }
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Simulate a key being pressed down and immediately released.
        /// </summary>
        /// <param name="ch">Key character to simulate.</param>
        public static void KeyPress(char ch)
        {
            short virtualKeyCode = VkKeyScan(ch);

            byte modifiers = Win32.HighByte(virtualKeyCode);

            VKey vKey = (VKey)Win32.LowByte(virtualKeyCode);

            if (modifiers == 0)
            {
                KeyPress(vKey);
            }
            else
            {
                KeyPress(vKey, modifiers);
            }
        }
Ejemplo n.º 23
0
        public void KeyPress(VKey key, List <VKey> pressedKeys)
        {
            Sound sound = ResolveShortcut(key, pressedKeys, _configurationModel.SelectedPreset.SoundCollection.Where(x => x.Files.Count != 0));

            if (sound != null)
            {
                _configurationModel.SelectedPreset.SelectedSound = sound;
                _soundManager.Play(sound);
            }

            Preset preset = ResolveShortcut(key, pressedKeys, _configurationModel.PresetCollection);

            if (preset != null)
            {
                _configurationModel.SelectedPreset = preset;
            }
        }
Ejemplo n.º 24
0
        public static string GetKeyDescription(VKey key)
        {
            FieldInfo fi = key.GetType().GetField(key.ToString());

            DescriptionAttribute[] attributes =
                (DescriptionAttribute[])fi.GetCustomAttributes(
                    typeof(DescriptionAttribute),
                    false);

            if (attributes != null && attributes.Length > 0)
            {
                return(attributes[0].Description);
            }
            else
            {
                return(key.ToString());
            }
        }
Ejemplo n.º 25
0
        public static KeyEvent[] ToKeyboardInput(this string input)
        {
            List <KeyEvent> events       = new List <KeyEvent>();
            ShiftState      pressedState = ShiftState.NONE;

            for (int i = 0; i < input.Length; i++)
            {
                ShiftState newState;
                VKey       key = GetVirtualKey(input[i], out newState);

                if (!newState.Equals(pressedState))            //state is different from current one
                {
                    if (!pressedState.Equals(ShiftState.NONE)) //release all keys
                    {
                        events.AddRange(pressedState.ToEvents(false));
                    }

                    if (!newState.Equals(ShiftState.NONE)) //press new keys
                    {
                        events.AddRange(newState.ToEvents(true));
                    }

                    pressedState = newState;
                }

                KeyEvent down = new KeyEvent {
                    keycode = key, downpress = true
                };
                KeyEvent up = new KeyEvent {
                    keycode = key, downpress = false
                };

                events.Add(down);
                events.Add(up);
            }

            if (!pressedState.Equals(ShiftState.NONE)) //release last keys
            {
                events.AddRange(pressedState.ToEvents(false));
            }

            return(events.ToArray());
        }
Ejemplo n.º 26
0
        public static KeyEvent[] ToEvents(this ShiftState shift, bool downpress)
        {
            List <KeyEvent> events = new List <KeyEvent>();

            ShiftState[] flags = new ShiftState[] { ShiftState.ALT, ShiftState.CTRL, ShiftState.HANKAKU, ShiftState.SHIFT };
            VKey[]       mapto = new VKey[] { VKey.ALT, VKey.CONTROL, VKey.UNDEFINED, VKey.SHIFT };

            for (int i = 0; i < flags.Length; i++)
            {
                if ((shift | flags[i]) > 0)
                {
                    events.Add(new KeyEvent()
                    {
                        keycode = mapto[i], downpress = downpress
                    });
                }
            }

            return(events.ToArray());
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Determines if a given virtual key is an extended key.
        /// </summary>
        /// <param name="vKey">Virtual key in question.</param>
        /// <returns>true if the virtual key is an extended key, otherwise false.</returns>
        public static bool IsExtendedKey(VKey vKey)
        {
            switch (vKey)
            {
            case VKey.VK_UP:
            case VKey.VK_DOWN:
            case VKey.VK_LEFT:
            case VKey.VK_RIGHT:
            case VKey.VK_HOME:
            case VKey.VK_END:
            case VKey.VK_PRIOR:
            case VKey.VK_NEXT:
            case VKey.VK_INSERT:
            case VKey.VK_DELETE:
                return(true);

            default:
                return(false);
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Simulate a key being pressed down and immediately released.
        /// </summary>
        /// <param name="vKey">Virtual key to simulate.</param>
        /// <param name="alt">Simulate alt key.</param>
        /// <param name="ctrl">Simulate control key.</param>
        /// <param name="shift">Simulate shift key.</param>
        /// <param name="winKey">Simulate windows key.</param>
        public static void KeyPress(VKey vKey, bool alt, bool ctrl, bool shift, bool winKey)
        {
            if (alt)
            {
                KeyDown(VKey.VK_MENU);
            }
            if (ctrl)
            {
                KeyDown(VKey.VK_CONTROL);
            }
            if (shift)
            {
                KeyDown(VKey.VK_SHIFT);
            }
            if (winKey)
            {
                KeyDown(VKey.VK_LWIN);
            }

            KeyPress(vKey);

            if (winKey)
            {
                KeyUp(VKey.VK_LWIN);
            }
            if (shift)
            {
                KeyUp(VKey.VK_SHIFT);
            }
            if (ctrl)
            {
                KeyUp(VKey.VK_CONTROL);
            }
            if (alt)
            {
                KeyUp(VKey.VK_MENU);
            }
        }
Ejemplo n.º 29
0
        private void OnKeyPressed(object sender, InputEventArg e)
        {
            VKey key = (VKey)e.KeyPressEvent.VKey;

            if (e.KeyPressEvent.Message == 256 || e.KeyPressEvent.Message == 260)
            {
                if (!(key == VKey.SHIFT && pressedKeys.Contains(key)))
                {
                    if (shiftNumpadCorrection && numpadKeys.ContainsKey(key))
                    {
                        shiftNumpadTimer.Stop();
                        shiftNumpadCorrection = false;
                        Key_Down(numpadKeys[key]);
                    }
                    else
                    {
                        Key_Down(key);
                    }
                }
            }
            else if (e.KeyPressEvent.Message == 257 || e.KeyPressEvent.Message == 261)
            {
                if (key == VKey.SHIFT)
                {
                    shiftNumpadTimer.Interval = 5;
                    shiftNumpadTimer.Start();
                    shiftNumpadCorrection = true;
                }
                else if (!pressedKeys.Contains(key) && numpadKeys.ContainsKey(key))
                {
                    Key_Up(numpadKeys[key]);
                }
                else
                {
                    Key_Up(key);
                }
            }
        }
Ejemplo n.º 30
0
        public void KeyPress(VKey key, List <VKey> pressedKeys)
        {
            if (_configurationModel.Enable == DisplayOption.Sounds || _configurationModel.Enable == DisplayOption.Both)
            {
                Sound sound = ResolveShortcut(key, pressedKeys, _configurationModel.SelectedPreset.SoundCollection.Where(x => x.Files.Count != 0));
                if (sound != null)
                {
                    _configurationModel.SelectedPreset.SelectedSound = sound;
                    _soundManager.Play(sound);
                }
            }

            Preset preset = ResolveShortcut(key, pressedKeys, _configurationModel.PresetCollection);

            if (preset != null)
            {
                _configurationModel.SelectedPreset = preset;
                foreach (Counter counter in preset.CounterCollection)
                {
                    counter.ReadFromFile();
                }
            }
        }
Ejemplo n.º 31
0
 public static extern short GetKeyState(VKey vkey);
Ejemplo n.º 32
0
    /// <summary>
    /// Simulate a key being pressed down and immediately released.
    /// </summary>
    /// <param name="vKey">Virtual key to simulate.</param>
    /// <param name="alt">Simulate alt key.</param>
    /// <param name="ctrl">Simulate control key.</param>
    /// <param name="shift">Simulate shift key.</param>
    /// <param name="winKey">Simulate windows key.</param>
    public static void KeyPress(VKey vKey, bool alt, bool ctrl, bool shift, bool winKey)
    {
      if (alt) KeyDown(VKey.VK_MENU);
      if (ctrl) KeyDown(VKey.VK_CONTROL);
      if (shift) KeyDown(VKey.VK_SHIFT);
      if (winKey) KeyDown(VKey.VK_LWIN);

      KeyPress(vKey);

      if (winKey) KeyUp(VKey.VK_LWIN);
      if (shift) KeyUp(VKey.VK_SHIFT);
      if (ctrl) KeyUp(VKey.VK_CONTROL);
      if (alt) KeyUp(VKey.VK_MENU);
    }
Ejemplo n.º 33
0
    /// <summary>
    /// Simulate a key being pressed down and immediately released.
    /// </summary>
    /// <param name="vKey">Virtual key to simulate.</param>
    /// <param name="modifiers">Key modifiers in effect.</param>
    public static void KeyPress(VKey vKey, byte modifiers)
    {
      bool alt = Win32.CheckMask(modifiers, (byte) KeyModifiers.Alt);
      bool ctrl = Win32.CheckMask(modifiers, (byte) KeyModifiers.Ctrl);
      bool shift = Win32.CheckMask(modifiers, (byte) KeyModifiers.Shift);

      KeyPress(vKey, alt, ctrl, shift, false);
    }
Ejemplo n.º 34
0
    /// <summary>
    /// Determines if a given virtual key is an extended key.
    /// </summary>
    /// <param name="vKey">Virtual key in question.</param>
    /// <returns>true if the virtual key is an extended key, otherwise false.</returns>
    public static bool IsExtendedKey(VKey vKey)
    {
      switch (vKey)
      {
        case VKey.VK_UP:
        case VKey.VK_DOWN:
        case VKey.VK_LEFT:
        case VKey.VK_RIGHT:
        case VKey.VK_HOME:
        case VKey.VK_END:
        case VKey.VK_PRIOR:
        case VKey.VK_NEXT:
        case VKey.VK_INSERT:
        case VKey.VK_DELETE:
          return true;

        default:
          return false;
      }
    }
Ejemplo n.º 35
0
 /// <summary>
 /// Gets the character that maps to the Virtual Key provided.
 /// </summary>
 /// <param name="vKey">The virtual key.</param>
 /// <returns>The character.</returns>
 public static char GetCharFromVKey(VKey vKey)
 {
   return (char)MapVirtualKey((uint)vKey, MAPVK_VK_TO_CHAR);
 }
Ejemplo n.º 36
0
    /*
    /// <summary>
    /// Simulate a key being pressed down.
    /// </summary>
    /// <param name="vKey">Virtual key to press.</param>
    public static void KeyDown(VKey vKey)
    {
      keybd_event((byte)vKey, 0, (uint)KeyEvents.KeyDown, IntPtr.Zero);
    }

    /// <summary>
    /// Simulate a key being released.
    /// </summary>
    /// <param name="vKey">Virtual key to release.</param>
    public static void KeyUp(VKey vKey)
    {
      keybd_event((byte)vKey, 0, (uint)KeyEvents.KeyUp, IntPtr.Zero);
    }
    */

    /// <summary>
    /// Simulate a Virtual Key event.
    /// </summary>
    /// <param name="vKey">Virtual Key.</param>
    /// <param name="scan">Scan code.</param>
    /// <param name="flags">Event type.</param>
    /// <param name="extraInfo">Pointer to additional information.</param>
    public static void Event(VKey vKey, byte scan, KeyEvents flags, IntPtr extraInfo)
    {
      keybd_event((byte)vKey, scan, (uint)flags, extraInfo);
    }
Ejemplo n.º 37
0
    /// <summary>
    /// Simulate a key being pressed down and immediately released.
    /// </summary>
    /// <param name="vKey">Virtual key to simulate.</param>
    public static void KeyPress(VKey vKey)
    {
      bool isExtended = IsExtendedKey(vKey);

      uint scanCode = MapVirtualKey((uint) vKey, 0);

      if (isExtended)
      {
        keybd_event((byte) vKey, (byte) scanCode, (uint) KeyEvents.KeyDown | (uint) KeyEvents.ExtendedKey, IntPtr.Zero);
        keybd_event((byte) vKey, (byte) scanCode, (uint) KeyEvents.KeyUp | (uint) KeyEvents.ExtendedKey, IntPtr.Zero);
      }
      else
      {
        keybd_event((byte) vKey, (byte) scanCode, (uint) KeyEvents.KeyDown, IntPtr.Zero);
        keybd_event((byte) vKey, (byte) scanCode, (uint) KeyEvents.KeyUp, IntPtr.Zero);
      }
    }
Ejemplo n.º 38
0
 public static extern short GetKeyState(VKey nVirtKey);