Beispiel #1
0
        // KeyDown and KeyUp


        public void SetKeyPressed(int code, bool pressed)
        {
            if (MyKeyDown[code] == pressed || code < 1 || code > 255)
            {
                return;
            }
            MyKeyDown[code] = pressed;
            var input = new MouseKeyIO.INPUT[1];

            input[0].type = MouseKeyIO.INPUT_KEYBOARD;

            if (pressed)
            {
                input[0].ki = KeyInput((ushort)code, extendedKeyMap.Contains(code) ? MouseKeyIO.KEYEVENTF_EXTENDEDKEY : 0);
            }
            else
            {
                if (extendedKeyMap.Contains(code))
                {
                    input[0].ki = KeyInput((ushort)code,
                                           MouseKeyIO.KEYEVENTF_EXTENDEDKEY | MouseKeyIO.KEYEVENTF_KEYUP);
                }
                else
                {
                    input[0].ki = KeyInput((ushort)code, MouseKeyIO.KEYEVENTF_KEYUP);
                }
            }
            MouseKeyIO.NativeMethods.SendInput(1, input, Marshal.SizeOf(input[0].GetType()));
        }
Beispiel #2
0
        // ButtonDown and ButtonUp
        public void SetButtonPressed(int button, bool pressed)
        {
            if (MyKeyDown[button] == pressed)
            {
                return;
            }
            MyKeyDown[button] = pressed;

            uint btn_flag;
            int  mousedata  = 0;
            var  reelbutton = button - (int)Mouse.Left;
            var  up         = !pressed ? 2 : 1;

            if (reelbutton == 3 || reelbutton == 4)
            {
                mousedata = reelbutton - 3 + (int)MouseKeyIO.XBUTTON1;
            }

            btn_flag = (mousedata > 0 ? MouseKeyIO.MOUSEEVENTF_XDOWN : MouseKeyIO.MOUSEEVENTF_LEFTDOWN << (reelbutton * 2)) * (uint)up;

            var input = new MouseKeyIO.INPUT[1];

            input[0].type = MouseKeyIO.INPUT_MOUSE;
            input[0].mi   = MouseInput(0, 0, (uint)mousedata, 0, btn_flag);
            MouseKeyIO.NativeMethods.SendInput(1, input, Marshal.SizeOf(input[0].GetType()));
        }
Beispiel #3
0
        public override void DoBeforeNextExecute()
        {
            KeyboardDevice.GetCurrentState(ref KeyState);


            if (Wheelturn != 0)
            {
                setPressedStrategy.Add(Wheelturn < 0 ? (int)Mouse.WheelBwd : (int)Mouse.WheelFwd);
                Wheelturn = Wheelturn - Math.Sign(Wheelturn);
            }

            if (Tempo != null && Tempo[0].GetLapse() >= Tempo[1])
            {
                Tempo[0] = StopTimer();
                Tempo    = null;
                foreach (var code in Codes.Reverse())
                {
                    KeyOrButtonUp(code);
                }
                Codes = null;
            }

            setPressedStrategy.Do();
            CheckScriptTimer();

            if ((cmd == 'I') && setPressedStrategy.IsListEmpty())
            {
                if (SF == null)
                {
                    SF = new ScriptKeyboardAndMouse(this);
                }
                SF.KeyboardAndMouse();
            }

            // If a mouse command was given in the script, issue it all at once right here
            if ((int)deltaXOut != 0 || (int)deltaYOut != 0 || wheel != 0)
            {
                var input = new MouseKeyIO.INPUT[1];
                input[0].type = MouseKeyIO.INPUT_MOUSE;
                input[0].mi   = MouseInput((int)deltaXOut, (int)deltaYOut, (uint)wheel, 0, MouseKeyIO.MOUSEEVENTF_MOVE | MouseKeyIO.MOUSEEVENTF_WHEEL);

                MouseKeyIO.NativeMethods.SendInput(1, input, Marshal.SizeOf(input[0].GetType()));

                // Reset the mouse values
                if ((int)deltaXOut != 0)
                {
                    deltaXOut = deltaXOut - (int)deltaXOut;
                }
                if ((int)deltaYOut != 0)
                {
                    deltaYOut = deltaYOut - (int)deltaYOut;
                }

                wheel = 0;
            }
            currentMouseState = null;  // flush the mouse state
        }
Beispiel #4
0
        public override void DoBeforeNextExecute()
        {
            CheckScriptTimer();

            if (cmd == 'M')
            {
                if (SF == null)
                {
                    //SF = new ScriptMouse(this);
                }
                SF.Mouse();
            }
            // If a mouse command was given in the script, issue it all at once right here
            if ((int)deltaXOut != 0 || (int)deltaYOut != 0 || wheel != 0)
            {
                var input = new MouseKeyIO.INPUT[1];
                input[0].type = MouseKeyIO.INPUT_MOUSE;
                input[0].mi   = MouseInput((int)deltaXOut, (int)deltaYOut, (uint)wheel, 0, MouseKeyIO.MOUSEEVENTF_MOVE | MouseKeyIO.MOUSEEVENTF_WHEEL);

                DLL.SendInput(1, input, Marshal.SizeOf(input[0].GetType()));

                // Reset the mouse values
                if ((int)deltaXOut != 0)
                {
                    deltaXOut = deltaXOut - (int)deltaXOut;
                }
                if ((int)deltaYOut != 0)
                {
                    deltaYOut = deltaYOut - (int)deltaYOut;
                }

                wheel = 0;
            }

            currentMouseState = null;  // flush the mouse state

            setPressedStrategy.Do();
        }
Beispiel #5
0
        public void SetButtonPressed(int button, bool pressed)
        {
            uint btn_flag = 0;

            if (button == 0)
            {
                if (pressed)
                {
                    if (!leftPressed)
                    {
                        btn_flag = MouseKeyIO.MOUSEEVENTF_LEFTDOWN;
                    }
                }
                else
                {
                    if (leftPressed)
                    {
                        btn_flag = MouseKeyIO.MOUSEEVENTF_LEFTUP;
                    }
                }
                leftPressed = pressed;
            }
            else if (button == 1)
            {
                if (pressed)
                {
                    if (!rightPressed)
                    {
                        btn_flag = MouseKeyIO.MOUSEEVENTF_RIGHTDOWN;
                    }
                }
                else
                {
                    if (rightPressed)
                    {
                        btn_flag = MouseKeyIO.MOUSEEVENTF_RIGHTUP;
                    }
                }
                rightPressed = pressed;
            }
            else
            {
                if (pressed)
                {
                    if (!middlePressed)
                    {
                        btn_flag = MouseKeyIO.MOUSEEVENTF_MIDDLEDOWN;
                    }
                }
                else
                {
                    if (middlePressed)
                    {
                        btn_flag = MouseKeyIO.MOUSEEVENTF_MIDDLEUP;
                    }
                }
                middlePressed = pressed;
            }

            if (btn_flag != 0)
            {
                var input = new MouseKeyIO.INPUT[1];
                input[0].type = MouseKeyIO.INPUT_MOUSE;
                input[0].mi   = MouseInput(0, 0, 0, 0, btn_flag);

                MouseKeyIO.NativeMethods.SendInput(1, input, Marshal.SizeOf(input[0].GetType()));
            }
        }