C# 如何创建脚本,以相对于当前鼠标位置以45度角自动移动鼠标

C# 如何创建脚本,以相对于当前鼠标位置以45度角自动移动鼠标,c#,macros,autohotkey,C#,Macros,Autohotkey,因此,该程序的目的是,在按下xbutton2时,我希望该程序自动将鼠标移动到与鼠标当前位置成45度角的位置,然后自动按下K键 我正在考虑让.ahk脚本运行一个获取鼠标位置,然后将相对移动移动到X和Y坐标,但是它不起作用,因为任何已经就位的移动都会覆盖它 我还从另一个编码器那里得到了一个C#脚本,他能够实现类似的输出,但是它在游戏中不起作用,也不是为同样的目的而构建的(可以重新调整用途),如果有帮助的话,我将包括粘贴库 >C#代码 这是我的密码: *xbutton2:: Mouse

因此,该程序的目的是,在按下xbutton2时,我希望该程序自动将鼠标移动到与鼠标当前位置成45度角的位置,然后自动按下K键

我正在考虑让.ahk脚本运行一个获取鼠标位置,然后将相对移动移动到X和Y坐标,但是它不起作用,因为任何已经就位的移动都会覆盖它

我还从另一个编码器那里得到了一个C#脚本,他能够实现类似的输出,但是它在游戏中不起作用,也不是为同样的目的而构建的(可以重新调整用途),如果有帮助的话,我将包括粘贴库

>C#代码

这是我的密码:

*xbutton2::
        MouseGetPos, x, y
        MouseMove, x+5.5, y+6.5
        MouseMove, x+5.5, y+6.5
        Send K
return```

几年前,我在一个应用程序中使用了什么来艰难地控制其他应用程序:

   public class Win32Input
    {
        [DllImport("user32.dll", EntryPoint = "SendInput", SetLastError = true)]
        static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);

        private enum InputType
        {
            INPUT_MOUSE = 0,
            INPUT_KEYBOARD = 1,
            INPUT_HARDWARE = 2,
        }

        [Flags()]
        private enum MOUSEEVENTF
        {
            MOVE = 0x0001,  // mouse move 
            LEFTDOWN = 0x0002,  // left button down
            LEFTUP = 0x0004,  // left button up
            RIGHTDOWN = 0x0008,  // right button down
            RIGHTUP = 0x0010,  // right button up
            MIDDLEDOWN = 0x0020,  // middle button down
            MIDDLEUP = 0x0040,  // middle button up
            XDOWN = 0x0080,  // x button down 
            XUP = 0x0100,  // x button down
            WHEEL = 0x0800,  // wheel button rolled
            VIRTUALDESK = 0x4000,  // map to entire virtual desktop
            ABSOLUTE = 0x8000,  // absolute move
        }

        [StructLayout(LayoutKind.Sequential)]
        private struct MOUSEINPUT
        {
            public int dx;
            public int dy;
            public int mouseData;
            public MOUSEEVENTF dwFlags;
            public int time;
            public IntPtr dwExtraInfo;
        }

        [StructLayout(LayoutKind.Sequential)]
        private struct INPUT
        {
            public InputType type;
            public MOUSEINPUT mi;
        }

        public static uint Move(int x, int y)
        {
            float ScreenWidth = Screen.PrimaryScreen.Bounds.Width;
            float ScreenHeight = Screen.PrimaryScreen.Bounds.Height;

            INPUT input_move = new INPUT();
            input_move.type = InputType.INPUT_MOUSE;

            input_move.mi.dx = (int)Math.Round(x * (65535 / ScreenWidth), 0);
            input_move.mi.dy = (int)Math.Round(y * (65535 / ScreenHeight), 0);
            input_move.mi.mouseData = 0;
            input_move.mi.dwFlags = (MOUSEEVENTF.MOVE | MOUSEEVENTF.ABSOLUTE);
            input_move.mi.time = 0;
            input_move.mi.dwExtraInfo = GetMessageExtraInfo();

            INPUT[] input = { input_move };
            return SendInput(1, input, Marshal.SizeOf(input_move));
        }
    }

我记得从互联网资源复制了这段代码。可能是这样。

如果要将其移动45度,则x中的位移应等于y,因此:

xbutton2::
        MouseGetPos, x, y
        MouseMove, x+6.5, y+6.5
        MouseMove, x+6.5, y+6.5
        Send K
return
我猜你的位移对你来说还可以,也许你的问题是你在玩一个游戏,它会影响AHK正确移动和发送钥匙的能力。是另一个更详细讨论的论坛

你还说动作被覆盖了。您是否一次运行多个AHK脚本?如果是这样的话,也许其中一个会陷入困境(发生在我身上)


希望有帮助

你的代码有什么问题?在什么方面不起作用?AHK代码中有很多问题,但是在我开始解决它们之前,你能解释一下你到底想要什么样的行为吗?目前,代码看起来像是将鼠标指针在x轴上移动5.5像素,在y轴上移动6.5像素。由于半像素不存在,甚至不认为它是不可能的,这看起来很奇怪。按下XButton2时只移动一次?拿着的时候不动吗?或者类似的?