Exemplo n.º 1
0
        public void sendKey(int scanCode, bool press)
        {
            KEYBOARD_INPUT[] input = new KEYBOARD_INPUT[1];
            input[0]       = new KEYBOARD_INPUT();
            input[0].type  = INPUT_KEYBOARD;
            input[0].flags = 0x0008;/* KEY_SCANCODE;*/

            if ((scanCode & 0xFF00) == 0xE000)
            { // extended key?
                input[0].flags |= KEY_EXTENDED;
            }

            if (press)
            { // press?
                input[0].scanCode = (ushort)(scanCode /*& 0xFF*/);
            }
            else
            { // release?
                input[0].scanCode = (ushort)scanCode;
                input[0].flags   |= KEY_UP;
            }

            uint result = SendInput(1, input, Marshal.SizeOf(input[0]));

            if (result != 1)
            {
                throw new Exception("Could not send key: " + scanCode);
            }
        }
Exemplo n.º 2
0
        private static void SendKey(int scanCode, bool press)
        {
            KEYBOARD_INPUT[] input = new KEYBOARD_INPUT[1];
            input[0]       = new KEYBOARD_INPUT();
            input[0].type  = INPUT_KEYBOARD;
            input[0].flags = KEYEVENTF_UNICODE;

            if ((scanCode & 0xFF00) == 0xE000)
            { // extended key?
                input[0].flags |= KEY_EXTENDED;
            }

            if (press)
            { // press?
                input[0].scanCode = (ushort)(scanCode & 0xFF);
            }
            else
            { // release?
                input[0].scanCode = (ushort)scanCode;
                input[0].flags   |= KEY_UP;
            }

            uint result = SendInput(1, input, Marshal.SizeOf(input[0]));

            if (result != 1)
            {
                Logger.Info("Could not send key" + result);
            }
        }
Exemplo n.º 3
0
        private void button6_Click(object sender, EventArgs e)
        {
            KEYBOARD_INPUT ex = new KEYBOARD_INPUT();

            textBox2.Text = string.Format("{0} wVk\r\n{1} wSc\r\n{2} Flags\r\n{3} Time\r\n{4} dwExtraInfo\r\n{5} Padding1\r\n{6} Padding2",
                                          (int)Marshal.OffsetOf(typeof(KEYBOARD_INPUT), "wVk"),
                                          (int)Marshal.OffsetOf(typeof(KEYBOARD_INPUT), "wSc"),
                                          (int)Marshal.OffsetOf(typeof(KEYBOARD_INPUT), "Flags"),
                                          (int)Marshal.OffsetOf(typeof(KEYBOARD_INPUT), "Time"),
                                          (int)Marshal.OffsetOf(typeof(KEYBOARD_INPUT), "dwExtraInfo"),
                                          (int)Marshal.OffsetOf(typeof(KEYBOARD_INPUT), "Padding1"),
                                          (int)Marshal.OffsetOf(typeof(KEYBOARD_INPUT), "Padding2"));
        }
        /// <summary>
        /// Calls the Win32 SendInput method to simulate a Key DOWN.
        /// </summary>
        /// <param name="keyCode">The VirtualKeyCode to press</param>
        private static void SimulateKeyDown(ushort keyCode)
        {
            const uint INPUT_KEYBOARD = 0x01;

            KEYBOARD_INPUT[] input = new KEYBOARD_INPUT[1];
            input[0]           = new KEYBOARD_INPUT();
            input[0].type      = INPUT_KEYBOARD;
            input[0].vk        = keyCode;
            input[0].scanCode  = 0;
            input[0].flags     = 0;
            input[0].time      = 0;
            input[0].extrainfo = 0;

            uint result = SendInput(1, input, Marshal.SizeOf(input[0]));

            if (result == 0)
            {
                throw new Exception(string.Format("The key down simulation for {0} was not successful.", keyCode));
            }
        }
Exemplo n.º 5
0
        public void sendKey(int scanCode, bool press)
        {
            KEYBOARD_INPUT[] input = new KEYBOARD_INPUT[1];
            input[0] = new KEYBOARD_INPUT();
            input[0].type = INPUT_KEYBOARD;
            input[0].flags = 0x0008;/* KEY_SCANCODE;*/

            if ((scanCode & 0xFF00) == 0xE000)
            { // extended key?
                input[0].flags |= KEY_EXTENDED;
            }

            if (press)
            { // press?
                input[0].scanCode = (ushort)(scanCode /*& 0xFF*/);
            }
            else
            { // release?
                input[0].scanCode = (ushort)scanCode;
                input[0].flags |= KEY_UP;
            }

            uint result = SendInput(1, input, Marshal.SizeOf(input[0]));

            if (result != 1)
            {
                throw new Exception("Could not send key: " + scanCode);
            }
        }