所以这个程序的目的是,当我按下xbutton2时,我想让程序自动将我的鼠标相对于鼠标的当前位置移动45度角,然后自动按K键。
我曾考虑让.akk脚本运行一个获取鼠标位置然后相对移动到一个X和Y坐标的程序,但是它没有工作,因为任何已经存在的移动会覆盖它。
我还从另一个开发人员那里得到了一个C#脚本,他能够实现类似的输出,但是它在游戏中没有功能,而且不是为了同样的目的而建立的(可以重新使用),如果有帮助的话,我将包括粘贴栏。
https:/pastebin.comdxXKfQpj > 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));
}
}
我记得我从互联网资源中复制了这段代码。可能是SO。
如果你想移动45度,应该是x中的位移等于y,所以 。
xbutton2::
MouseGetPos, x, y
MouseMove, x+6.5, y+6.5
MouseMove, x+6.5, y+6.5
Send K
return
我猜你的位移对你来说是OK的,也许你的问题是你在玩一个游戏,它歪曲了AHK正确移动和发送键的能力。这里是 是另一个论坛在谈论更多的细节。
你还说动作是被覆盖的,你是否在运行多个AHK脚本?你是否同时运行多个AHK脚本?如果是这样的话,也许其中一个脚本会卡在一个循环中(我就遇到过)。
希望这能帮到你