コード例 #1
0
        public void WriteText(string characters)
        {
            var inputs = new NativeMethods.INPUT[2 * characters.Length];

            for (int i = 0; i < inputs.Length; i++)
            {
                var ki = new NativeMethods.KEYBDINPUT
                {
                    dwFlags = NativeMethods.KEYEVENTF.UNICODE
                };
                if (i % 2 == 1)
                {
                    ki.dwFlags |= NativeMethods.KEYEVENTF.KEYUP;
                }
                ki.wScan = (short)characters[i / 2];

                var input = new NativeMethods.INPUT();
                input.type = NativeMethods.INPUT_KEYBOARD;
                input.U.ki = ki;

                inputs[i] = input;
            }

            if (NativeMethods.SendInput((uint)inputs.Length, inputs, NativeMethods.INPUT.Size) == 0)
            {
                throw new Win32Exception();
            }
        }
コード例 #2
0
        private void PressOrReleaseKey(VirtualKeyShort keyCode, bool down)
        {
            var ki = new NativeMethods.KEYBDINPUT
            {
                wVk = keyCode
            };

            if (!down)
            {
                ki.dwFlags = NativeMethods.KEYEVENTF.KEYUP;
            }

            var input = new NativeMethods.INPUT();

            input.type = NativeMethods.INPUT_KEYBOARD;
            input.U.ki = ki;

            NativeMethods.INPUT[] inputs = { input };

            if (NativeMethods.SendInput((uint)inputs.Length, inputs, NativeMethods.INPUT.Size) == 0)
            {
                throw new Win32Exception();
            }
        }
コード例 #3
0
        public void WriteText(string characters)
        {
            NativeMethods.INPUT[] inputs = new NativeMethods.INPUT[2 * characters.Length];
            for (int i = 0; i < inputs.Length; i++)
            {
                var ki = new NativeMethods.KEYBDINPUT();
                ki.dwFlags = NativeMethods.KEYEVENTF.UNICODE;
                if (i % 2 == 1)
                    ki.dwFlags |= NativeMethods.KEYEVENTF.KEYUP;
                ki.wScan = (short)characters[i / 2];

                var input = new NativeMethods.INPUT();
                input.type = NativeMethods.INPUT_KEYBOARD;
                input.U.ki = ki;

                inputs[i] = input;
            }

            if (NativeMethods.SendInput((uint)inputs.Length, inputs, NativeMethods.INPUT.Size) == 0)
                throw new System.ComponentModel.Win32Exception();
        }
コード例 #4
0
        private void PressOrReleaseKey(VirtualKeyShort keyCode, bool down)
        {
            var ki = new NativeMethods.KEYBDINPUT();
            ki.wVk = keyCode;
            if (!down)
                ki.dwFlags = NativeMethods.KEYEVENTF.KEYUP;

            var input = new NativeMethods.INPUT();
            input.type = NativeMethods.INPUT_KEYBOARD;
            input.U.ki = ki;

            NativeMethods.INPUT[] inputs = { input };

            if (NativeMethods.SendInput((uint)inputs.Length, inputs, NativeMethods.INPUT.Size) == 0)
                throw new System.ComponentModel.Win32Exception();
        }