C# 在光标隐藏时移动鼠标
我目前正在创建一个非常小的应用程序,它可以防止我在minecraft服务器上被afk踢。它的工作原理是,每x秒它就会来回移动我的鼠标。 即使它在技术上工作得很好,但当我在Minecraft时它不会移动我的鼠标。它只会移动我的鼠标,如果光标实际可见。在ingame中,光标是隐藏的,因此无法工作。 要实际移动鼠标,请使用:C# 在光标隐藏时移动鼠标,c#,winforms,C#,Winforms,我目前正在创建一个非常小的应用程序,它可以防止我在minecraft服务器上被afk踢。它的工作原理是,每x秒它就会来回移动我的鼠标。 即使它在技术上工作得很好,但当我在Minecraft时它不会移动我的鼠标。它只会移动我的鼠标,如果光标实际可见。在ingame中,光标是隐藏的,因此无法工作。 要实际移动鼠标,请使用: Point location = new Point(System.Windows.Forms.Cursor.Position.X+moveAmount, System.Wind
Point location = new Point(System.Windows.Forms.Cursor.Position.X+moveAmount, System.Windows.Forms.Cursor.Position.Y);
System.Windows.Forms.Cursor.Position = location;
有人有什么想法吗?为什么它在Minecraft中不起作用?我如何修复它
我在stackoverflow上发现了这个问题,但即使这样也不起作用:
[DllImport("user32.dll")]
static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
private const int MOUSEEVENTF_MOVE = 0x0001;
public static void Move(int xDelta, int yDelta)
{
mouse_event(MOUSEEVENTF_MOVE, xDelta, yDelta, 0, 0);
}
好的,我确实做到了。 经过一些研究和尝试许多不同的东西后,这是有效的:
[Flags]
public enum MouseEventFlags {
LeftDown = 0x00000002,
LeftUp = 0x00000004,
MiddleDown = 0x00000020,
MiddleUp = 0x00000040,
Move = 0x00000001,
Absolute = 0x00008000,
RightDown = 0x00000008,
RightUp = 0x00000010
}
[DllImport("user32.dll")]
private static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
public static void MouseEvent(MouseEventFlags value, MousePoint position2) {
MousePoint position = position2;
mouse_event
((int)value,
position.X,
position.Y,
0,
0)
;
}
[StructLayout(LayoutKind.Sequential)]
public struct MousePoint {
public int X;
public int Y;
public MousePoint(int x, int y) {
X = x;
Y = y;
}
}
如何调用该方法:
MouseEvent(MouseEventFlags.Move, new MousePoint { X = 100, Y = 100 });
对不起,我不玩这个游戏,但是你如何移动角色?也许你可以利用左右方向的箭头点击来移动它?嘿,谢谢你的回答。可悲的是,这并不能解决我的问题。只是左右移动并不能阻止我被踢。我必须移动鼠标。移动头部可能会给你一些指导:游戏使用原始输入来阻止用户作弊。因此,他们只看到来自设备驱动程序的输入,而不使用光标、鼠标位置、事件或SendInput。功能,不是一个bug。但是有没有一个解决方案可以让它在像Minecraft这样的游戏中工作呢?