Exemplo n.º 1
0
        /// <summary>
        /// Sends a directx key.
        /// http://www.gamespp.com/directx/directInputKeyboardScanCodes.html
        /// </summary>
        /// <param name="key"></param>
        /// <param name="KeyUp"></param>
        /// <param name="inputType"></param>
        public static void SendKey(DirectXKeyStrokes key, bool KeyUp, InputType inputType)
        {
            uint flagtosend;

            if (KeyUp)
            {
                flagtosend = (uint)(KeyEventF.KeyUp | KeyEventF.Scancode);
            }
            else
            {
                flagtosend = (uint)(KeyEventF.KeyDown | KeyEventF.Scancode);
            }

            Input[] inputs =
            {
                new Input
                {
                    type = (int)inputType,
                    u    = new InputUnion
                    {
                        ki = new KeyboardInput
                        {
                            wVk         = 0,
                            wScan       = (ushort)key,
                            dwFlags     = flagtosend,
                            dwExtraInfo = GetMessageExtraInfo()
                        }
                    }
                }
            };

            SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(Input)));
        }
Exemplo n.º 2
0
        private async void PressButton(DirectXKeyStrokes key, int durationMs)
        {
            SendKey(key, false, InputType.Keyboard);
            await Task.Delay(durationMs);

            SendKey(key, true, InputType.Keyboard);
            await Task.Delay(POST_UP_DELAY_MS);

            depressedKeys.Remove(key);
        }
Exemplo n.º 3
0
        public bool TriggerKeyPress(DirectXKeyStrokes key, int durationMs)
        {
            if (!depressedKeys.Add(key))
            {
                return(false);
            }

            PressButton(key, durationMs);

            return(true);
        }
Exemplo n.º 4
0
 public static void SendEchoKey(DirectXKeyStrokes key, bool holdShift = false, bool focusEchoVR = true)
 {
     if (focusEchoVR)
     {
         Program.FocusEchoVR();
     }
     if (holdShift)
     {
         SendKey(DirectXKeyStrokes.DIK_LSHIFT, false, InputType.Keyboard);
     }
     SendKey(key, false, InputType.Keyboard);
     Task.Delay(50).ContinueWith((_) =>
     {
         SendKey(key, true, InputType.Keyboard);
         if (holdShift)
         {
             SendKey(DirectXKeyStrokes.DIK_LSHIFT, true, InputType.Keyboard);
         }
     });
 }
Exemplo n.º 5
0
 /// <summary>
 /// Sends a directx key.
 /// </summary>
 public static void SendKey(DirectXKeyStrokes key, bool KeyUp)
 {
     SendKey((ushort)key, KeyUp);
 }