我正在尝试编写脚本,我对 Lua 和脚本编写都是全新的。这将用于单击并拖动(移动项目)、返回、单击并再次拖动。然后按住鼠标左键(5 秒)。然后休息1.5秒。我想重复使用 G1 键(如果 G 键不能正常工作,则使用另一个键)作为使用 GHub 的罗技键盘上的开关。我收到一个脚本错误,我不知道这是否很容易修复。
谢谢。
function OnEvent(event, arg)
if event == "G_PRESSED" and arg == 1 then
if script_running then
script_running = false
return
else
script_running = true
end
MoveMouseTo(130, 250)
PressMouseButton(1)
repeat
MoveMouseTo(800, 850)
ReleaseMouseButton(1)
MoveMouseTo (200, 250)
PressMouseButton(1)
repeat
MoveMouseTo (800, 850)
ReleaseMouseButton(1)
PressMouseButton(1)
Sleep(5000)
ReleaseMouseButton(1)
Sleep (1500)
until not script_running
end
end
首先,打开 GHub 并将操作“返回”分配给罗技键盘上的物理键 G1。
(“后退”是鼠标按钮 #4 的默认操作,因此 G1 将复制其功能,我假设游戏忽略了鼠标按钮 #4)
-- Set your screen resolution here
local screen_width = 1920
local screen_height = 1080
local active, exit
local function SleepG1(ms)
local tm = GetRunningTime() + ms
repeat
Sleep(10)
local G1 = IsMouseButtonPressed(4) -- 4 = "Back"
active, exit = G1, exit or G1 and not active
until GetRunningTime() > tm
end
local function MoveMouseToPixels(x, y)
-- x, y from 0,0 to 1919,1079
x = math.max(0, math.min(screen_width - 1, math.floor(x * 65535 / (screen_width - 1) + 0.5)))
y = math.max(0, math.min(screen_height - 1, math.floor(y * 65535 / (screen_height - 1) + 0.5)))
MoveMouseTo(x, y)
end
function OnEvent(event, arg)
if event == "G_PRESSED" and arg == 1 then
active = not active
if active then
exit = false
Sleep(10)
repeat
-- click and drag (moving an item)
MoveMouseToPixels(130, 250) -- in pixels
SleepG1(50)
PressMouseButton(1)
SleepG1(50)
MoveMouseToPixels(800, 850) -- in pixels
SleepG1(50)
ReleaseMouseButton(1)
SleepG1(50)
-- click and drag again
MoveMouseToPixels(200, 250) -- in pixels
SleepG1(50)
PressMouseButton(1)
SleepG1(50)
MoveMouseToPixels(800, 850) -- in pixels
SleepG1(50)
ReleaseMouseButton(1)
SleepG1(50)
-- press left mouse button and hold (5 seconds)
PressMouseButton(1)
SleepG1(5000)
ReleaseMouseButton(1)
SleepG1(50)
-- rest for 1.5 seconds.
SleepG1(1500)
until exit
active = true
end
end
end