赞
踩
尽管我们基本只需要使用罗技现成的接口简单的编程,但编程所使用的lua脚本语言基于C语言开发,仍需掌握编程语言的基本语法,可参考C语言菜鸟教程
在掌握着C语言语法的前提下,Lua有着一些细小的区别,在使用循环等语句时需正确使用。可参考Lua菜鸟教程
罗技已经写好了很多的现成的操作接口,我们主要使用G-series Lua API文档中的函数。中文文档可参考罗技G系列宏命令编程参考
G HUB是罗技官方提供的驱动软件,最后需通过此软件导入我们编写的配置文件。罗技官方对国内下载支持不太友好,网上有很多下载时容易遇到的问题的解决方案,可自行搜索。G HUB下载点这里
我使用的是罗技G Wireless Pro鼠标,其键位图如下,其中G6位于鼠标底部
代码如下:
local recoil = false
--recoil为开关变量
local Xstep = {-3,0,5,-4,-7, -8,-5,-6,2,8, 4,0,2,0,-4, -2,-3,4,4,2, 2,3,-4,-5,-5, -2}
local Ystep = {13,13,8,13,21, 14,12,13,11,11, 10,7,10,6,4, 4,2,5,3,6, 4,3,2,2,1, 3}
local Tstep = 55
local capacity = 26
--Xstep和Ystep为每发子弹移动的像素数组,正方向分别为向右和向下
--Tstep为射击间隔
--capacity为满弹夹时子弹容量-1
EnablePrimaryMouseButtonEvents(true)
--启用鼠标主键(即左键)事件报告
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
--监听到鼠标事件时向控制台输出
if (event == "MOUSE_BUTTON_PRESSED" and arg == 7) then
recoil = not recoil
OutputLogMessage("recoil = %s\n",recoil)
end
--当按下7号键时,改变开关变量(切换开关状态)
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil == true) then
Sleep(4)
for i=1,capacity do
if(IsMouseButtonPressed(1) == false) then
OutputLogMessage("break\n")
break
end
MoveMouseRelative(Xstep[i],Ystep[i])
Sleep(Tstep)
end
OutputLogMessage("end\n")
end
--当按下1号键时,按序执行压枪数组,松开或弹夹为0后结束压枪
end
对于固定弹道的游戏,在输入了合适的Xstep,Ystep,Tstep和capacity后可实现完美压枪,仅供学习。鼠标宏等同于外挂!会导致封号,禁止在多人游戏中使用
以上代码是一发一发子弹压枪,对于非固定弹道时,单向的拖动鼠标可以达到粗糙的压枪效果,可使用以下代码:
local recoil = false
local Xstep = 3
local Ystep = 22
EnablePrimaryMouseButtonEvents(true)
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if (event == "MOUSE_BUTTON_PRESSED" and arg == 7) then
recoil = not recoil
OutputLogMessage("recoil = %s\n",recoil)
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil == true) then
Sleep(4)
while(IsMouseButtonPressed(1))
do
Sleep(1)
MoveMouseRelative(Xstep,Ystep)
Sleep(10)
end
end
end
需注意,新版GHUB中脚本代码应删除全部中文注释,否则会报错,文章代码中“- -”后的为注释。
https://blog.csdn.net/qq_41090038/article/details/108221352
https://www.cnblogs.com/huic/p/14057206.html
学习过程中参考了以上两篇文章,特此致谢
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。