예제 #1
0
        public static uint Send(this IEnumerable <Input> inputs, TimeSpan AfterSleep)
        {
            var x = User32Helpers.SendInput(inputs.ToArray());

            Thread.Sleep(AfterSleep);
            return(x);
        }
예제 #2
0
 public static void SendMouseClick()
 {
     Input[] m_inputs = new Input[2];
     Input.InitMouseInput(out m_inputs[0], 0, 0, MouseInputFlags.MOUSEEVENTF_LEFTDOWN, 0, 0);
     Input.InitMouseInput(out m_inputs[1], 0, 0, MouseInputFlags.MOUSEEVENTF_LEFTUP, 0, 50);
     var x = User32Helpers.SendInput(m_inputs);
 }
예제 #3
0
        public static void SendSingleKey(Input[] m_inputs)
        {
            var x = User32Helpers.SendInput(m_inputs);

            Input.InitKeyboardInput(out m_inputs[0], VirtualKey.H, false);

            //Input.InitKeyboardInput(out m_inputs[0], , false);
            //Input.InitMouseInput(out m_inputs[0],0,0,0);
        }
예제 #4
0
        private static void SendKey(string key)
        {
            Input inputKey = new Input();

            inputKey.Type = InputType.INPUT_KEYBOARD;
            inputKey.Packet.KeyboardInput.VirtualKeyCode = (ushort)VkKeyScan(char.Parse(key));
            inputKey.Packet.KeyboardInput.Flags          = KeyboardInputFlags.KEYEVENTF_UNICODE;
            inputKey.Packet.KeyboardInput.ScanCode       = char.Parse(key);
            User32Helpers.SendInput(new[] { inputKey });
            inputKey.Packet.KeyboardInput.Flags = KeyboardInputFlags.KEYEVENTF_UNICODE |
                                                  KeyboardInputFlags.KEYEVENTF_KEYUP;
            User32Helpers.SendInput(new[] { inputKey });
        }
예제 #5
0
        private static void SendShift(bool press)
        {
            Input inputShift = new Input();
            uint  shiftKey   = MapVirtualKey((uint)Keys.ShiftKey, 0x0);

            inputShift.Type = InputType.INPUT_KEYBOARD;
            inputShift.Packet.KeyboardInput.Flags = KeyboardInputFlags.KEYEVENTF_SCANCODE;
            if (!press)
            {
                inputShift.Packet.KeyboardInput.Flags |= KeyboardInputFlags.KEYEVENTF_KEYUP;
            }

            inputShift.Packet.KeyboardInput.ScanCode = (ushort)shiftKey;

            User32Helpers.SendInput(new[] { inputShift });
        }
예제 #6
0
파일: Program.cs 프로젝트: zyj0021/WinApi
            protected override void OnCreate(ref CreateWindowPacket packet)
            {
                this.m_textBox = StaticBox.Create(
                    "Ahoy!",
                    hParent: this.Handle);

                this.m_editBox = EditBox.Create(
                    "Nothing here yet.",
                    hParent: this.Handle,
                    controlStyles:
                    EditBox.EditStyles.ES_MULTILINE | EditBox.EditStyles.ES_WANTRETURN |
                    (EditBox.EditStyles)WindowStyles.WS_VSCROLL);

                this.m_layout.ClientArea = this.GetClientRect();
                this.m_layout.Margin     = new Rectangle(10, 10, 10, 10);
                this.m_layout.Children.Add(this.m_textBox);
                this.m_layout.Children.Add(this.m_editBox);
                this.m_layout.PerformLayout();
                this.m_timerProc = (wnd, uMsg, eventId, millis) =>
                {
                    try
                    {
                        this.m_timesExecuted++;
                        Input.InitKeyboardInput(out this.m_inputs[0], VirtualKey.H, false);
                        Input.InitKeyboardInput(out this.m_inputs[1], VirtualKey.H, true);
                        Input.InitKeyboardInput(out this.m_inputs[3], VirtualKey.E, false);
                        Input.InitKeyboardInput(out this.m_inputs[4], VirtualKey.E, true);
                        Input.InitKeyboardInput(out this.m_inputs[5], VirtualKey.L, false);
                        Input.InitKeyboardInput(out this.m_inputs[6], VirtualKey.L, true);
                        Input.InitKeyboardInput(out this.m_inputs[7], VirtualKey.L, false);
                        Input.InitKeyboardInput(out this.m_inputs[8], VirtualKey.L, true);
                        Input.InitKeyboardInput(out this.m_inputs[9], VirtualKey.O, false);
                        Input.InitKeyboardInput(out this.m_inputs[10], VirtualKey.O, true);
                        var x = User32Helpers.SendInput(this.m_inputs);
                    }
                    catch (Exception ex) {
                        this.m_editBox.SetText($"ERROR: {ex.Message}\r\n{ex.StackTrace}");
                    }
                };

                this.m_timerId = User32Methods.SetTimer(this.Handle, IntPtr.Zero, 20, this.m_timerProc);
                base.OnCreate(ref packet);
            }