- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在delphi中编写一个程序来模拟以特定速度移动的鼠标指针(类似于AutoIT MouseMove函数)。要么是我的代码错误,要么是 SetCursorPos 在被调用太多次后出现故障。这是我的功能:
procedure MoveMouse ( X, Y, Speed : Integer);
var
P : TPoint;
NewX : Integer;
NewY : Integer;
begin
if X < 0 then exit;
if Y < 0 then exit;
if X > Screen.Height then exit;
if Y > Screen.Width then Exit;
repeat
GetCursorPos(P);
NewX := P.X;
NewY := P.Y;
if P.X <> X then begin
if P.X > X then begin
NewX := P.X - 1;
end else begin
NewX := P.X + 1;
end;
end;
if P.Y <> Y then begin
if P.Y > Y then begin
NewY := P.Y - 1;
end else begin
NewY := P.Y + 1;
end;
end;
sleep (Speed);
SetCursorPos(NewX, NewY);
until (P.X = X) and (P.Y = Y);
end;
我这样使用它:
procedure TForm1.btn1Click(Sender: TObject);
var
X : Integer;
Y : Integer;
begin
for X := 0 to Screen.Width do begin
for Y := 0 to Screen.Height do begin
MouseClick (X, Y, 1);
end;
end;
end;
由于某种原因,鼠标指针卡在某个 X 点,然后跳回 0,0,但这是为什么?
最佳答案
你的代码被卡住了,因为在重复循环中,条件
until (P.X = X) and (P.Y = Y);
当您传递值 X=0 和 Y=Screen.Height 时,永远不会满足,因此您必须修改循环以仅传递有效的屏幕坐标值
for X := 0 to Screen.Width-1 do
for Y := 0 to Screen.Height-1 do
MoveMouse (X, Y, 1);
您还可以改进检查GetCursorPos
结果的方法。和 SetCursorPos
功能。
procedure MoveMouse ( X, Y, Speed : Word);
var
P : TPoint;
NewX : Integer;
NewY : Integer;
begin
if X > Screen.Width-1 then Exit;
if Y > Screen.Height-1 then Exit;
repeat
if not GetCursorPos(P) then RaiseLastOSError;
NewX := P.X;
NewY := P.Y;
if P.X <> X then
begin
if P.X > X then
NewX := P.X - 1
else
NewX := P.X + 1;
end;
if P.Y <> Y then
begin
if P.Y > Y then
NewY := P.Y - 1
else
NewY := P.Y + 1
end;
Sleep (Speed);
if not SetCursorPos(NewX, NewY) then RaiseLastOSError;
until (P.X = X) and (P.Y = Y);
end;
关于delphi - SetCursorPos 故障?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14310040/
我想在delphi中编写一个程序来模拟以特定速度移动的鼠标指针(类似于AutoIT MouseMove函数)。要么是我的代码错误,要么是 SetCursorPos 在被调用太多次后出现故障。这是我的功
我正在使用以下库:http://www.codeproject.com/Articles/28064/Global-Mouse-and-Keyboard-Library?fid=1518257&df=
我创建了一个类似于 wiimote 的设备,我想将它用作 windows (8.1) 中的鼠标。该设备通过 tcp 连接到我的 windows 计算机上的 c++ win32 程序,并发送鼠标光标应该
当我尝试在 Windows Vista/7 登录屏幕上使用 SetCursorPos 时,返回了 true,这起初让我认为它正在工作。但是,当我调用 GetCursorPos 时,它会给我: -858
这个问题在这里已经有了答案: How to use Rundll32 to execute DLL Function? (1 个回答) 关闭 7 年前。 如何从 Windows RunDll32 应
我正在尝试使用 SetCursorPos 在光标到达屏幕边缘时移动光标位置(对于 scrubby 控件);标准的“跟踪直到边缘被击中,将光标移动到屏幕中间”。 问题是 Windows 在收到鼠标事件后
当在 WM_INPUT 事件中读取鼠标位置时,鼠标光标被隐藏,当通过远程桌面使用应用程序时,SetCursorPos 似乎不起作用。 当应用程序不通过远程桌面使用时,同样的代码也能正常工作。即,我可以
使用以下两种技术在窗口中移动鼠标有什么区别吗? win32api.SetCursorPos((x,y)) 对比: nx = x*65535/win32api.GetSystemMetrics(0) n
我一直在尝试将鼠标光标置于 Mac OSX El capitan 10.11.2 上。我做了一些挖掘,发现有很多方法有些已被弃用,有些是新的。尝试了很多例子,但到目前为止都没有成功。 这是我到目前为止
我在尝试更新相机时遇到问题。 我想通过鼠标改变相机的俯仰和偏航(它看起来的地方)但我希望鼠标保持在窗口的中心。 //where MouseP.x .y is the mouse position //
有什么区别吗 System.Windows.Forms.Cursor.Position and setCursorPos 一个或另一个的使用真的会影响鼠标移动的速度吗?谢谢。 最佳答案 System.
Cursor.Position、SetCursorPos()、SendInput() 和 mouse_event() 都将鼠标位置设置为指定坐标。 那么它们有什么区别呢? 最佳答案 Cursor.Po
我是一名优秀的程序员,十分优秀!