This document provides a concise reference for the Logitech G HUB Lua API, version 2023.5. It's designed for quick lookups of function specifications and usage examples.
Handles script events. You must implement this function.
Specification:
function OnEvent(event, arg [family])
endParameters:
event(string): The event identifier.arg(varies): Argument related to the event.family(string, optional): Device family ("kb", "lhc", "mouse").
Events:
| Event | arg |
family |
Description |
|---|---|---|---|
"PROFILE_ACTIVATED" |
nil |
Profile activated. This is the first event seen. | |
"PROFILE_DEACTIVATED" |
nil |
Profile deactivated. This is the last event seen. | |
"G_PRESSED" |
1-18 (G1-G18) | G Key pressed. | |
"G_RELEASED" |
1-18 (G1-G18) | G Key released. | |
"M_PRESSED" |
1-3 (M1-M3) | M Key pressed. | |
"M_RELEASED" |
1-3 (M1-M3) | M Key released. | |
"MOUSE_BUTTON_PRESSED" |
2+ | "mouse" | Mouse button pressed (except left by default, see EnablePrimaryMouseButtonEvents). |
"MOUSE_BUTTON_RELEASED" |
2+ | "mouse" | Mouse button released (except left by default, see EnablePrimaryMouseButtonEvents). |
Example:
function OnEvent(event, arg, family)
if event == "PROFILE_ACTIVATED" then
OutputLogMessage("Profile activated\n")
elseif event == "G_PRESSED" and arg == 1 then
OutputLogMessage("G1 key pressed\n")
end
endGets the current state of the M keys.
Specification:
mkey = GetMKeyState([family])Parameters:
family(string, optional): Device family ("kb", "lhc"). Default is "kb".
Return Value:
mkey(number): 1 (M1), 2 (M2), or 3 (M3).
Example:
local currentMKey = GetMKeyState()
OutputLogMessage("Current M key state: %d\n", currentMKey)Sets the current state of the M keys.
Specification:
SetMKeyState(mkey, [family])Parameters:
mkey(number): 1 (M1), 2 (M2), or 3 (M3).family(string, optional): Device family ("kb", "lhc"). Default is "kb".
Example:
function OnEvent(event, arg)
if event == "G_PRESSED" and arg == 1 then
SetMKeyState(1) -- Set M key state to M1
end
endPauses the script for a specified duration.
Specification:
Sleep(timeout)Parameters:
timeout(number): Time to sleep in milliseconds.
Example:
Sleep(100) -- Pause for 100 millisecondsSends a formatted message to the script editor's console.
Specification:
OutputLogMessage(...)Parameters:
...(string):printf-style formatted string and arguments.
Example:
OutputLogMessage("Hello, world! This is a number: %d\n", 42)Returns the script's running time in milliseconds.
Specification:
elapsed = GetRunningTime()Return Value:
elapsed(number): Elapsed time in milliseconds.
Example:
local runningTime = GetRunningTime()
OutputLogMessage("Script has been running for %d ms\n", runningTime)Retrieves the formatted date and time.
Specification:
date = GetDate([format [, time]])Parameters:
format(string, optional): Date format string (strftime style). "*t" for table format.time(table, optional): Time table.
Return Value:
date(string or table): Formatted date/time.
Example:
local today = GetDate("%Y-%m-%d %H:%M:%S")
OutputLogMessage("Today's date and time: %s\n", today)Clears the script editor's output window.
Specification:
ClearLog()Example:
ClearLog()Simulates a keyboard key press.
Specification:
PressKey(scancode [, scancode ...])
PressKey(keyname [, keyname ...])Parameters:
scancode(number): Numerical scancode of the key.keyname(string): Predefined keyname. (See Appendix A in the documentation for a complete list of scancodes and keynames.)
Example:
PressKey("a") -- Press the "a" key
PressKey(30) -- Press the key with scancode 30 ("a")
PressKey("shift", "a") -- Press Shift and "a" togetherSimulates a keyboard key release.
Specification:
ReleaseKey(scancode [, scancode ...])
ReleaseKey(keyname [, keyname ...])Parameters:
scancode(number): Numerical scancode of the key.keyname(string): Predefined keyname.
Example:
ReleaseKey("a") -- Release the "a" key
ReleaseKey(30) -- Release the key with scancode 30Simulates a keyboard key press followed by a release.
Specification:
PressAndReleaseKey(scancode [, scancode ...])
PressAndReleaseKey(keyname [, keyname ...])Parameters:
scancode(number): Numerical scancode of the key.keyname(string): Predefined keyname.
Example:
PressAndReleaseKey("a") -- Press and release "a"Checks if a modifier key (Alt, Shift, Ctrl) is pressed.
Specification:
boolean = IsModifierPressed(keyname)Parameters:
keyname(string): "lalt", "ralt", "alt", "lshift", "rshift", "shift", "lctrl", "rctrl", "ctrl".
Return Value:
boolean(boolean):trueif pressed,falseotherwise.
Example:
if IsModifierPressed("shift") then
OutputLogMessage("Shift key is pressed\n")
endChecks if a lock key (Scroll Lock, Caps Lock, Num Lock) is enabled.
Specification:
boolean = IsKeyLockOn(keyname)Parameters:
keyname(string): "scrolllock", "capslock", "numlock".
Return Value:
boolean(boolean):trueif enabled,falseotherwise.
Example:
if IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock") -- Turn off Num Lock
endSimulates a mouse button press.
Specification:
PressMouseButton(button)Parameters:
button(number): 1 (Left), 2 (Middle), 3 (Right), 4 (X1), 5 (X2).
Example:
PressMouseButton(1) -- Press the left mouse buttonSimulates a mouse button release.
Specification:
ReleaseMouseButton(button)Parameters:
button(number): 1 (Left), 2 (Middle), 3 (Right), 4 (X1), 5 (X2).
Example:
ReleaseMouseButton(1) -- Release the left mouse buttonSimulates a mouse button press followed by a release.
Specification:
PressAndReleaseMouseButton(button)Parameters:
button(number): 1 (Left), 2 (Middle), 3 (Right), 4 (X1), 5 (X2).
Example:
PressAndReleaseMouseButton(1) -- Click the left mouse buttonChecks if a mouse button is pressed.
Specification:
boolean = IsMouseButtonPressed(button)Parameters:
button(number): 1 (Left), 2 (Middle), 3 (Right), 4 (X1), 5 (X2).
Return Value:
boolean(boolean):trueif pressed,falseotherwise.
Example:
if IsMouseButtonPressed(3) then
OutputLogMessage("Right mouse button is pressed\n")
endMoves the mouse cursor to an absolute screen position.
Specification:
MoveMouseTo(x, y)Parameters:
x(number): Normalized X coordinate (0-65535).y(number): Normalized Y coordinate (0-65535).
Example:
MoveMouseTo(0, 0) -- Move to top-left cornerSimulates mouse wheel movement.
Specification:
MoveMouseWheel(clicks)Parameters:
clicks(number): Number of clicks (positive for up, negative for down).
Example:
MoveMouseWheel(3) -- Scroll up 3 clicks
MoveMouseWheel(-1) -- Scroll down 1 clickMoves the mouse cursor relative to its current position.
Specification:
MoveMouseRelative(x, y)Parameters:
x(number): X-axis movement (positive for right, negative for left).y(number): Y-axis movement (positive for down, negative for up).
Example:
MoveMouseRelative(10, -5) -- Move 10 pixels right and 5 pixels upMoves the mouse cursor to an absolute position on a multi-monitor setup.
Specification:
MoveMouseToVirtual(x, y)Parameters:
x(number): Normalized X coordinate (0-65535).y(number): Normalized Y coordinate (0-65535).
Example:
MoveMouseToVirtual(32767, 32767) -- Move to the center of the virtual desktopGets the current normalized mouse cursor position.
Specification:
x, y = GetMousePosition()Return Values:
x(number): Normalized X coordinate (0-65535).y(number): Normalized Y coordinate (0-65535).
Example:
local x, y = GetMousePosition()
OutputLogMessage("Mouse position: x=%d, y=%d\n", x, y)Not implemented in G HUB. Sets the DPI table for a gaming mouse.
Specification:
SetMouseDPITable({value1, value2, ...}, [index])Parameters:
{value1, value2, ...}(table): Array of DPI values.index(number, optional): 1-based index to set as current DPI.
Not implemented in G HUB. Sets the current DPI table index.
Specification:
SetMouseDPITableIndex(index)Parameters:
index(number): 1-based index into the DPI table.
Enables or disables event reporting for the primary (left) mouse button.
Specification:
EnablePrimaryMouseButtonEvents(enable)Parameters:
enable(boolean):trueto enable,falseto disable.
Example:
EnablePrimaryMouseButtonEvents(true) -- Enable left mouse button eventsNote: These functions are not implemented in G HUB.
Adds a line of text to the LCD.
Specification:
OutputLCDMessage(text [, timeout])Parameters:
text(string): Text to display.timeout(number, optional): Timeout in milliseconds (default 1000).
Clears the LCD.
Specification:
ClearLCD()Plays an existing macro.
Specification:
PlayMacro(macroname)Parameters:
macroname(string): Name of the macro.
Example:
PlayMacro("my_macro")Plays a macro by simulating a key press down.
Specification:
PressMacro(macroname)Parameters:
macroname(string): Name of the macro.
Example:
PressMacro("my_macro")Plays a macro by simulating a key release.
Specification:
ReleaseMacro(macroname)Parameters:
macroname(string): Name of the macro.
Example:
ReleaseMacro("my_macro")Aborts a currently playing macro started from a script.
Specification:
AbortMacro()Example:
PlayMacro("my_macro")
Sleep(100)
AbortMacro()Not implemented in G HUB. Sets the backlight color for supported devices.
Specification:
SetBacklightColor(red, green, blue, [family])Parameters:
red(number): Red intensity (0-255).green(number): Green intensity (0-255).blue(number): Blue intensity (0-255).family(string, optional): "kb", "lhc".
Not implemented in G HUB. Sets properties for steering wheel devices (G29, G920).
Specification:
SetSteeringWheelProperty(device, property, value)Parameters:
device(string): "G29" or "G920".property(string): "operatingRange", "combinedPedals", "defaultCenteringSpring", "defaultCenteringSpringStrength".value(number or boolean): Property value.
Note: These functions are not implemented in G HUB.
Sets the analog joystick mouse speed on the G13.
Specification:
SetMouseSpeed(speed)Parameters:
speed(number): Absolute mouse speed (32-255).
Gets the current analog joystick mouse speed on the G13.
Specification:
speed = GetMouseSpeed()Return Value:
speed(number): Current mouse speed.
Increases the analog joystick mouse speed.
Specification:
IncrementMouseSpeed(increment)Parameters:
increment(number): Increment value.
Decreases the analog joystick mouse speed.
Specification:
DecrementMouseSpeed(decrement)Parameters:
decrement(number): Decrement value.
Sends a message to the Windows debugger.
Specification:
OutputDebugMessage(...)Parameters:
...(string):printf-style formatted string and arguments.
Example:
OutputDebugMessage("This is a debug message: %d\n", 123)The following standard Lua 5.4 libraries are supported. For detailed information, refer to the Lua 5.4 documentation: