Try to use function SmoothMoveMouseTo(x_in_pixels, y_in_pixels)
instead of MoveMouseTo()
-- set your game screen resolution here
local width = 1920
local height = 1080
function SmoothMoveMouseTo(x_target, y_target)
local speed = 1000 -- mouse cursor speed in pixels per second
local prev_dist = math.huge
local attempts = 0
repeat
local tm = GetRunningTime()
Sleep(10)
local x, y = GetMousePosition()
tm = (GetRunningTime() - tm) * .001
x = x_target - math.max(0, math.min(width, math.floor(x * (width - 1) / 65535 + .5)))
y = y_target - math.max(0, math.min(height, math.floor(y * (height - 1) / 65535 + .5)))
local ax, ay = math.abs(x), math.abs(y)
if ax < 1 and ay < 1 then
break
end
local dist = (x*x + y*y) ^.5
local dx = math.floor(math.min(ax, math.max(-ax, speed * x / dist * tm)) + .5)
local dy = math.floor(math.min(ay, math.max(-ay, speed * y / dist * tm)) + .5)
MouseMoveRelative(dx, dy)
if dist < prev_dist then
prev_dist = dist
attempts = 0
else
attempts = attempts + 1
end
until attempts > 10
end
function OnEvent(event, arg)
.... (your code here)
end
For example, SmoothMoveMouseTo(1920/2, 1080/2)
to move to the center of the screen
MoveMouseTo(0,0)
should immediately move the cursor to the upper left corner of the screen. What behavior do you see instead?