G系列Lua API是一组使用Lua编程语言的函数,该语言提G系列游戏键盘和鼠标的高级脚本功能。
	本文档假定具备Lua编程语言的实用知识。进一步的有关信息,请访问www.lua.org。
	每个G系列配置文件都绑定了一个默认的Lua脚本,可以进行编辑和自定义。
	脚本是使用事件处理程序调用的:OnEvent。用户可以查看各种事件在该处理程序中公开以执行其所需的操作。

参考

Functions

OnEvent

OnEvent()函数用作脚本的事件处理程序。您需要实施这个功能。

function OnEvent(event, arg [family])
end

参数
event
包含事件标识符的字符串。
arg
与相应标识符相关的参数。
family
创建硬件事件的设备系列。如果事件不是硬件,则为空。具体的如果需要区分多个设备的输入,请使用此选项。

FamilyDevices
“kb”支持的键盘设备
“lhc”支持的左手控制器
“mouse”支持的游戏鼠标

返回值
None
备注
以下是标识符及其参数的列表:

EventargDescription
“PROFILE_ACTIVATED”NoneProfile has been activated.This is the first event seen.
“PROFILE_DEACTIVATED”NoneProfile has been deactivated.This is the last event seen.
“G_PRESSED”1=G1 18=G18 n = GnG Key pressed
“G_RELEASED”1=G1 18=G18 n = GnG Key pressed
“M_PRESSED”1=M1 2=M2 3=M3M Key pressed
“M_RELEASED”1=M1 2=M2 3=M3M Key pressed
“MOUSE_BUTTON_PRESSED”2=Mouse Button 2 3=Mouse Button 3 4=Mouse Button 4 …Mouse Button Pressed NOTE: Left Mouse Button (1) is not reported by default. Use ‘EnablePrimaryMouseButtonEvents’ to override this.
“MOUSE_BUTTON_RELEASED”2=Mouse Button 2 3=Mouse Button 3 4=Mouse Button 4 …Mouse Button Pressed NOTE: Left Mouse Button (1) is not reported by default. Use ‘EnablePrimaryMouseButtonEvents’ to override this.

示例

-- This is the primary event handler. You must implement this function
function OnEvent(event, arg)
if (event == "PROFILE_ACTIVATED") then
-- Profile has been activated
end
if (event == "PROFILE_DEACTIVATED") then
-- Profile has been deactivated
end
if (event == "G_PRESSED" and arg == 1) then
-- G1 has been pressed
end
if (event == "G_RELEASED" and arg == 1) then
-- G1 has been released
end
if (event == "M_PRESSED" and arg == 1) then
-- M1 has been pressed
end
if (event == "M_RELEASED" and arg == 1) then
-- M1 has been released
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 6) then
-- Mouse Button 6 has been pressed
end
if (event == "MOUSE_BUTTON_RELEASED" and arg == 6) then
-- Mouse Button 6 has been released
end
end

GetMKeyState

GetMKeyState()返回当前状态下的Mkey值

mkey GetMKeyState([family])

参数
family
如果要区分多个,则设备的可选系列名称连接的设备。默认值为“kb”。

FamilyDevices
“kb”支持的键盘设备
“lhc”支持的左手控制器

返回值
mkey
1 = M1, 2 = M2, 3 = M3
备注

示例

-- Get the current M Key state
current_mkey = GetMKeyState()

SetMKeyState

SetMKeyState()设置M个键的当前状态
注意:之后立即调用GetMKeyState可能会返回以前的状态。使用OnEvent处理程序,以确定操作何时完成。

mkey SetMKeyState(mkey, [family])

参数
mkey
1 = M1, 2 = M2, 3 = M3
family
如果要区分多个,则设备的可选系列名称连接的设备。默认值为“kb”。

FamilyDevices
“kb”支持的键盘设备
“lhc”支持的左手控制器

返回值
None
备注

示例

-- Set the current M Key state to M1 when G1 is pressed
function OnEvent(event, arg)
	if (event == "G_PRESSED" and arg == 1) then
		SetMkeyState(1)
	end
end

Sleep

Sleep()将导致脚本暂停所需的时间。

Sleep( timeout )

参数
timeout
睡眠总时间(毫秒)
返回值
nil
备注
脚本在主Profiler之外的另一个线程上运行,因此暂停脚本不会影响它。您可以使用此函数来模拟延迟。探查器的停用将等待1秒,等待脚本完成,然后脚本将被强制中止。如果使用长时间超时,请采取预防措施
示例

-- Sleeping for 20 milliseconds
Sleep(20)

OutputLogMessage

OutputLogMessage()将向脚本编辑器的控制台发送日志消息。

OutputLogMessage( ... )

参数
message
包含消息的Printf样式格式化字符串。
返回值
nil
备注
string.format()的镜像。
您必须手动插入回车“\n”来表示行尾。
示例

-- Send out "Hello World"
OutputLogMessage("Hello World %d\n", 2007)

GetRunningTime

GetRunningTime()返回自脚本运行时间

elapsed GetRunningTime()

参数
None
返回值
elapsed
包含以毫秒为单位的运行时间的整数值。
备注
您可以使用它来计算脚本中的时间。
示例

-- Display the script running time
OutputLogMessage("This script has been running for: %d ms", GetRunningTime())

GetDate

使用GetDate()检索格式化日期

date GetDate ([format [, time]])

参数
format
可选日期格式字符串。。
time
可选时间表。
返回值
date
包含用户机器的当前日期和时间(或由时间表示的时间)、根据给定的字符串格式进行格式化。如果有希望提供自己的格式字符串,它使用与strftime()相同的规则。这个特殊字符串*t告诉date()函数返回一个表。
备注
映射os.date()
示例

-- Display the current date/time
OutputLogMessage("Today’s date/time is: %s\n", GetDate())

ClearLog

函数的作用是清除脚本编辑器的输出窗口。

ClearLog()

参数
None
返回值
nil
备注
None
示例

-- Clear the script editor log
OutputLogMessage("This message will self destruct in 2 seconds\n")
Sleep(2000)
ClearLog()

PressKey

PressKey()函数用于模拟点击键盘按键。
注意:对于模拟的,随后立即调用IsModifierPressed或IsKeyLockOn修改器或锁定键可能会返回以前的状态。这将需要几毫秒要完成的操作。

PressKey( scancode [,scancode] )
PressKey( keyname [,keyname] )

参数
scancode
指定要按下的键的数字扫描代码。
keyname
指定要按的键的预定义注释记号。
返回值
nil
备注
如果提供了多个键作为参数,则所有键都将通过按键进行模拟。有关扫描代码和注释记号的值,请参阅附录A。
示例

-- Simulate "a" pressed using the scancode
PressKey(30)
-- Simulate "a" pressed using the keyname
PressKey("a")
-- Simulate "a" and "b" being pressed
PressKey("a", "b")

ReleaseKey

ReleaseKey()函数用于模拟释放键盘按键。

ReleaseKey( scancode [,scancode] )
ReleaseKey( keyname [,keyname] )

参数
scancode
指定要按下的键的数字扫描代码。
keyname
指定要按的键的预定义注释记号。
返回值
nil
备注
如果提供了多个键作为参数,则所有键都将使用一个版本进行模拟。有关扫描代码和注释记号的值,请参阅附录A。
示例

-- Simulate "a" released using the scancode
ReleaseKey(30)
-- Simulate "a" released using the keyname
ReleaseKey("a")
-- Simulate "a" and "b" being released
ReleaseKey("a", "b")

PressAndReleaseKey

PressAndReleaseKey()函数用于模拟按下键盘键后释放
注意:对于模拟的,随后立即调用IsModifierPressed或IsKeyLockOn修改器或锁定键可能会返回以前的状态。这将需要几毫秒要完成的操作。

PressAndReleaseKey( scancode [,scancode] )
PressAndReleaseKey( keyname [,keyname] )

参数
scancode
指定要按下的键的数字扫描代码。
keyname
指定要按的键的预定义注释记号。
返回值
nil
备注
如果提供了多个键作为参数,则所有键都将使用一个版本进行模拟。有关扫描代码和注释记号的值,请参阅附录A。
示例

-- Simulate "a" pressed and released using the scancode
PressAndReleaseKey(30)
-- Simulate "a" pressed and released using the keyname
PressAndReleaseKey("a")
-- Simulate "a" and "b" being pressed and released
PressAndReleaseKey("a", "b")

IsModifierPressed

IsModifierPressed()函数用于确定特定的修饰符键当前是否在按下状态。

boolean IsModifierPressed ( keyname )

参数
keyname
指定要按的修改器键的预定义注释记号。名称必须是以下其中之一:

ModifierDescription
“lalt”, “ralt”, “alt”Left, right, or either Alt key
“lshift”, “rshift”, “shift”Left, right, or either Shift key
“lctrl”, “rctrl”, “ctrl”Left, right, or either Ctrl key

返回值
如果当前按下修改键,则为True,否则为false。
备注
None
示例

-- Press a specific modifier
PressKey("lshift")- Sleep for 100 ms to allow IsModifierPressed() to get an accurate result
Sleep(100)
if IsModifierPressed("shift") then
 OutputLogMessage("shift is pressed.\n")
end
-- Release the key so it is no longer pressed
ReleaseKey("lshift")- Sleep for 100 ms to allow IsModifierPressed() to get an accurate result
Sleep(100)
if not IsModifierPressed("shift") then
 OutputLogMessage("shift is not pressed.\n")
end

PressMouseButton

PressMouseButton()函数用于模拟鼠标按键。
注意:之后立即调用IsMouseButton Pressed,可能会返回上一个状态操作需要几毫秒才能完成。

PressMouseButton( button )

参数
button
按钮标识符。使用下表:

Button valueLocation
1Left Mouse Button
2Middle Mouse Button
3Right Mouse Button
4X1 Mouse Button
5X2 Mouse Button

返回值
nil
备注
None
示例

-- Simulate left mouse button press
PressMouseButton(1)
-- Simulate right mouse button press
PressMouseButton(3)

ReleaseMouseButton

ReleaseMouseButton()函数用于模拟鼠标按钮的释放

ReleaseMouseButton( button )

参数
button
按钮标识符。使用下表

Button valueLocation
1Left Mouse Button
2Middle Mouse Button
3Right Mouse Button
4X1 Mouse Button
5X2 Mouse Button

返回值
nil
备注
None
示例

-- Simulate a left mouse button click (press and release)
PressMouseButton(1)
ReleaseMouseButton(1)

ReleaseMouseButton( button )

PressAndReleaseMouseButton()函数用于模拟按下鼠标按钮然后释放。
注意:之后立即调用IsMouseButtonPressed可能会返回上一个状态操作需要几毫秒才能完成

PressAndReleaseMouseButton( button )

参数
button
按钮标识符。使用下表

Button valueLocation
1Left Mouse Button
2Middle Mouse Button
3Right Mouse Button
4X1 Mouse Button
5X2 Mouse Button

返回值
nil
备注
None
示例

-- Simulate a left mouse button click (press and release)
PressAndReleaseMouseButton(1)

IsMouseButtonPressed

IsMouseButton Pressed()函数用于确定特定鼠标按钮是否当前处于按下状态。

boolean IsMouseButtonPressed( button )

参数
button
按钮标识符。使用下表

Button valueLocation
1Left Mouse Button
2Middle Mouse Button
3Right Mouse Button
4X1 Mouse Button
5X2 Mouse Button

返回值
如果当前按下按钮,则为True,否则为false。
备注
None
示例

-- Press a mouse button
PressMouseButton(1)
if IsMouseButtonPressed(1) then
 OutputLogMessage("Left mouse button is pressed.\n")
end
-- Release the button so it is no longer pressed
ReleaseMouseButton(1) 
if not IsMouseButtonPressed(1) then
 OutputLogMessage("Left mouse button is not pressed.\n")
end

MoveMouseTo

MoveMouseTo()函数用于将鼠标光标移动到屏幕
注意:之后立即调用GetMousePosition,很可能会返回以前的状态。它操作将需要几毫秒才能完成。

MoveMouseTo( x, y, )

参数
x
0(最左边)和65535(最右边)之间的标准化X坐标
Y
Normalized y coordinate between 0 (farthest top) and 65535 (farthest bottom)
返回值
nil
备注
如果存在多个监视器,请使用MoveMouseToVirtual。
示例

-- Move mouse to upper, left corner
MoveMouseTo(0, 0)
-- Move mouse to center of screen
MoveMouseTo(32767, 32767)
-- Move mouse to lower, right corner
MoveMouseTo(65535, 65535)

MoveMouseWheel

MoveMouseWheel()函数用于模拟鼠标滚轮的移动。

MoveMouseWheel( click )

参数
click
鼠标滚轮单击次数。
返回值
nil
备注
正值表示车轮向上移动(远离用户)。
负值表示车轮向下移动(朝向用户)。
示例

-- Simulate mouse wheel 3 clicks up
MoveMouseWheel(3)
-- Simulate mouse wheel 1 click down
MoveMouseWheel(-1)

MoveMouseRelative

MoveMouseRelative()函数用于模拟鼠标的相对移动。
注意:之后立即调用GetMousePosition,可能会返回以前的状态。它操作将需要几毫秒才能完成。

MoveMouseRelative( x, y )

参数
x
沿x轴移动
Y
沿y轴移动
返回值
nil
备注
正x值模拟向右移动。
负x值模拟向左移动。
正y值模拟向下移动。
负y值模拟向上移动。
示例

-- Simulate relative mouse movement upwards in 1 pixel increments
for i = 0, 50 do
MoveMouseRelative(0, -1)
Sleep(8)
end

MoveMouseToVirtual

MoveMouseToVirtual()函数用于将鼠标光标移动到一个绝对位置在多监视器屏幕布局上。
注意:之后立即调用GetMousePosition,可能会返回以前的状态。它操作将需要几毫秒才能完成。

MoveMouseToVirtual( x, y )

参数
x
0(最左侧)和65535(最右侧)之间的归一化X坐标
Y
0(最远顶部)和65535(最远底部)之间的归一化y坐标
返回值
nil
备注
如果存在多个监视器,请使用MoveMouseToVirtual。
示例

-- Move mouse to upper, left corner of virtual desktop
MoveMouseToVirtual(0, 0)
-- Move mouse to center of virtual desktop
MoveMouseToVirtual(32767, 32767)
-- Move mouse to lower, right corner of virtual desktop
MoveMouseToVirtual(65535, 65535)

GetMousePosition

GetMousePosition()函数返回当前鼠标的标准坐标光标位置。

x,y GetMousePosition()

参数
nil
返回值
x
0(最左侧)和65535(最右侧)之间的归一化X坐标
Y
0(最远顶部)和65535(最远底部)之间的归一化y坐标
备注

示例

-- Get the current mouse cursor position
x, y = GetMousePosition()
OutputLogMessage("Mouse is at %d, %d\n", x, y)

OutputLCDMessage

OutputLCDMessage()函数用于在LCD上添加一行文本。

OutputLCDMessage( text [,timeout] )

参数
text
要显示的字符串
timeout
超时(毫秒),之后消息将消失
返回值
nil
备注
一次最多可以显示4行文本。默认超时为1秒。该功能未在G HUB中实现。
示例

-- Display some text with default timeout
OutputLCDMessage("Hello world")
-- Display some text for 2 seconds
OutputLCDMessage("Hello world", 2000)

ClearLCD

ClearLCD()函数用于清除LCD上的脚本显示。

ClearLCD( )

参数
none
返回值
nil
备注
该功能未在G HUB中实现。
示例

-- Clear the LCD and then display 2 lines of text
ClearLCD()
OutputLCDMessage("Hello world1")
OutputLCDMessage("Hello world2")

PlayMacro

PlayMacro()函数用于播放现有的宏。

PlayMacro( macroname )

参数
macroname
属于当前配置文件的现有宏的名称。
返回值
nil
备注
如果在播放另一个脚本宏时调用该函数,则不会执行任何操作。在其他单词,在任何给定时间只能播放一个脚本宏。如果在播放同一脚本宏时调用该函数,则该宏将排队。宏将模拟按键按下(在虚拟宏键上),等待100ms,然后模拟密钥释放。这样,宏将在印刷和发布时播放正确地要对宏播放进行精细控制,请查看PressMacro和释放宏函数。
示例

-- Play an existing macro
PlayMacro("my macro")

PressMacro

PressMacro()函数用于通过模拟按键按下来播放现有宏。

PressMacro( macroname )

参数
macroname
属于当前配置文件的现有宏的名称。
返回值
nil
备注
如果在播放另一个脚本宏时调用该函数,则不会执行任何操作。在其他单词,在任何给定时间只能播放一个脚本宏。如果在播放同一脚本宏时调用该函数,则该宏将排队。
示例

-- Play an existing macro
PressMacro("my macro")

ReleaseMacro

ReleaseMacro()函数用于通过模拟密钥释放来播放现有宏。

ReleaseMacro( macroname )

参数
macroname
属于当前配置文件的现有宏的名称。
返回值
nil
备注
如果在播放另一个脚本宏时调用该函数,则不会执行任何操作。在其他单词,在任何给定时间只能播放一个脚本宏。如果在播放同一脚本宏时调用该函数,则该宏将排队。
示例

-- Play an existing macro
ReleaseMacro("my macro")

AbortMacro

AbortMacro()函数用于中止从脚本启动的任何宏。

AbortMacro( )

参数
None
返回值
nil
备注
调用PlayMacro后仍按下的任何键都将被释放。外部播放的宏剧本将继续播放。
示例

-- Start a macro
PlayMacro("my macro")
-- Wait for 100ms and then abort any playing macro
Sleep(100)
AbortMacro()

IsKeyLockOn

IsKeyLockOn()函数用于确定特定的锁定按钮当前是否在启用状态。

IsKeyLockOn( key )

参数
key
key name。使用下表:

Key nameLocation
“scrolllock”Scroll Lock
“capslock”Caps Lock
“numlock”Number Lock

返回值
如果当前已启用锁定,则为True,否则为false
备注
None
示例

-- Check if the numlock is on and turn it off if it is
if IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end

SetBacklightColor

SetBacklightColor()函数用于设置设备的自定义背光颜色(如果设备支持自定义背光)。

SetBacklightColor(red, green, blue, [family])

参数
red
红色强度(0–255)
green
绿色强度(0–255)
blue
蓝色强度(0–255)
family
如果要区分多个,则设备的可选系列名称连接的设备。默认值为“kb”。

FamilyDevices
“kb”Keyboard devices (G15, G11, G19, etc)
“lhc”Keyboard devices (G15, G11, G19, etc)

返回值
nil
备注
此功能未在G HUB中实现
示例

-- Set the backlight to red
SetBacklightColor(255, 0, 0)
-- Set the backlight color for all left handed controllers to blue
SetBacklightColor(0, 0, 255, "lhc")

OutputDebugMessage

输出调试消息

OutputDebugMessage( ... )

参数
Message
Printf样式、格式化的包含消息的字符串。
返回值
nil
备注
string.format()的格式化。
您必须手动插入回车“\n”来表示行尾。
使用Dbg View等工具查看这些消息。
示例

-- Send out "Hello World"
OutputDebugMessage("Hello World %d\n", 2007)

SetMouseDPITable

SetMouseDPITable()为支持的游戏鼠标设置当前DPI表

SetMouseDPITable({value1, value2, value3}, [index])

参数
DPI Array
DPI值数组
DPI Index
可选的基于1的DPI索引,用作当前DPI。
返回值
nil
备注
如果未指定索引,则第一个条目将用作当前DPI。
最多允许16个条目。
使用每个配置文件的DPI设置激活配置文件将覆盖以前应用的任何DPI。
该功能未在G HUB中实现。
示例

-- Set our DPI values to {500, 1000, 1500, 2000, 2500}
-- By default, 500 DPI will be set as the current DPI
SetMouseDPITable({500, 1000, 1500, 2000, 2500})
-- Set our DPI values to {500, 2500} and set the second value as the current DPI
SetMouseDPITable({500, 2500}, 2)

SetMouseDPITableIndex

SetMouseDPITableIndex()为支持的游戏鼠标设置当前DPI表索引

SetMouseDPITableIndex(index)

参数
Index
1-基于DPI表的索引
返回值
nil
备注
如果在此之前未调用SetMouseDPITable,则使用鼠标的当前DPI表。
最多允许16个条目。
使用每个配置文件的DPI设置激活配置文件将覆盖以前应用的任何DPI。
该功能未在G HUB中实现。
示例

-- Set our initial DPI values to {500, 1000, 1500, 2000, 2500}
SetMouseDPITable({500, 1000, 1500, 2000, 2500})
-- Set the current DPI to the 3rd item in the table (1500 DPI)
SetMouseDPITableIndex(3)

EnablePrimaryMouseButtonEvents

EnablePrimaryMouseButtonEvents()启用鼠标按钮1的事件报告。

EnablePrimaryMouseButtonEvents(enable)

参数
enable
1或true可启用鼠标按钮1的事件报告
0或false可禁用鼠标按钮1的事件报告
返回值
nil
备注
默认情况下,对于性能问题,不会报告主鼠标按钮。
示例

-- Enable event reporting for mouse button 1
EnablePrimaryMouseButtonEvents(true)
-- Disable event reporting for mouse button 1
EnablePrimaryMouseButtonEvents(false)

SetSteeringWheelProperty

SetSteeringWheelProperty()设置方向盘属性。

SetSteeringWheelProperty(device, property, value)

参数
device

DeviceDescription
“G29”Logitech G29 Steering Wheel
“G920”Logitech G920 Steering Wheel

property

PropertyDescription
“operatingRange”Operating range of wheel from 40 to 900. Default is 900.
“combinedPedals”Combines the brake and accelerator into a single axis. The accelerator is on the + axis, and the brake is on the – axis. Default is false.
“defaultCenteringSpring”Plays a persistent spring on top of any game forces. Default is false.
“defaultCenteringSpringStrength”“defaultCenteringSpringStrength”

返回值
nil
备注
该功能未在G HUB中实现。
示例

-- Set the operating range to 200 degrees for the G29
SetSteeringWheelProperty("G29", "operatingRange", 200)
-- Enable combined pedals on the G920
SetSteeringWheelProperty("G920", "combinedPedals", true)

G13 Programming

G13游戏面板有一个模拟操纵杆,可以为其分配鼠标功能鼠标的速度可以通过设置中的profiler选项面板进行调整窗口,或者通过Lua脚本语言。以下是的新Lua函数鼠标速度控制:

SetMouseSpeed ()

参数
新鼠标速度
鼠标绝对速度32到255
返回值

备注
该功能未在G HUB中实现。

--Set Mouse speed to 128
SetMouseSpeed(128)

GetMouseSpeed()

参数
新鼠标速度
鼠标绝对速度32到255
返回值
当前模拟鼠标速度。
备注
该功能未在G HUB中实现。

--Get Mouse speed
OutputLogMessage("The Mouse Speeed is: %d\n", GetMouseSpeed())

IncrementMouseSpeed()

参数
鼠标速度增量
返回值

备注
结果鼠标速度将被限制为最大255
该功能未在G HUB中实现。

--Increase Mouse speed by 10
IncrementMouseSpeed(10)

DecrementMouseSpeed()

参数
鼠标速度递减
返回值

备注
由此产生的鼠标速度将被限制为最小32
该功能未在G HUB中实现。

-- Decrease Mouse speed by 10
DecrementMouseSpeed(10)

G13鼠标功能不支持任何本地按钮,等等。鼠标按钮必须通过Lua进行编程。下面是一个通用Lua代码的例子效果鼠标按钮操作:

if event=="G_PRESSED" and arg==x then
 PressMouseButton( y )
end
if event=="G_RELEASED" and arg==x then
 ReleaseMouseButton( y )

标准Lua 5.4库

支持以下标准库函数:

Math函数字符串函数表格函数
math.absstring.bytestring.byte
math.acosstring.chartable.insert
math.asinstring.dumptable.move
math.atanstring.findtable.pack
math.ceilstring.formattable.remove
math.cosstring.gmatchtable.sort
math.degstring.gsubtable.unpack
math.expstring.len
math.floorstring.lower
math.fmodstring.match
math.hugestring.pack
math.logstring.packsize
math.maxstring.rep
math.maxintegerstring.reverse
math.minstring.sub
math.minintegerstring.unpack
math.modfstring.uppe
math.pi
math.rad
math.random
math.randomseed
math.sin
math.sqrt
math.tan
math.tointeger
math.type
math.ult
Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐