Skip to content

jehillert/logitech-ghub-lua-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 

Repository files navigation

I see I have some stars on here, and that is great. But I did not put nearly enough effort into this as I could have. I spent a couple hours after supreme frustration with the lack of lua code examples. I thoroughly welcome contributions and pull requests suggesting edits, and contributing example scripts. It would be great if we could help Logitech gaming mice achieve just a little bit more of its potential. I doubt this kind of stuff is ever going to come from Logitech itself...

FUNCTIONS LISTING

  AbortMacro()
  ClearLog()
  EnablePrimaryMouseButtonEvent()
  OnEvent()
  GetDate()
  GetKeyState()
  GetMKeyState()
  GetMousePosition()
  GetRunningTime()
  IsKeyLockOn()
  IsModifierPressed()
  IsMouseButtonPressed()
  MoveMouseRelative()
  MoveMouseTo()
  MoveMouseToVirtual()
  MoveMouseWheel()
  OnEvent()
  OutputDebugMessage()
  OutputLCDMessage()
  OutputLogMessage()
  PlayMacro()
  PressAndReleaseKey()
  PressAndReleaseMouseButton()
  PressKey()
  PressMouseButton()
  ReleaseKey()
  ReleaseMouseButton()
  SetBacklightColor(
  SetMKeyState()
  SetMouseDPITable()
  SetMouseDPITableIndex()
  Sleep()

EVENTS

“MOUSE_BUTTON_PRESSED”      1|2|3|4|5|6   LB|MB|RB|XB1|XB2
“MOUSE_BUTTON_RELEASED”     1|2|3|4|5|6   LB|MB|RB|XB1|XB2
"G_PRESSED"|"G_RELEASED"    1|2|3…18      G1|G2|G3…G18
"M_PRESSED"|"M_RELEASED"    1|2|3         M1|M2|M3
"PROFILE_ACTIVATED"         none          none
"PROFILE_DEACTIVATED"       none          none
    ARG:MOUSE ==> 1:LB | 2:MB | 3:RB | 4:XB1 | 5:XB2

EVENT FLOW CONTROL

if (event == "PROFILE_ACTIVATED") then end
if (event == "PROFILE_DEACTIVATED") then end
if (event == "G_PRESSED" and arg == 1) then end
if (event == "G_RELEASED" and arg == 1) then end
if (event == "M_PRESSED" and arg == 1) then end
if (event == "M_RELEASED" and arg == 1) then end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 6) then end
if (event == "MOUSE_BUTTON_RELEASED" and arg == 6) then end

BASIC FLOW CONTROL [FN1]

function OnEvent(event, arg [, family])
  doStuff
end
if condition then
  doStuff
end
if not condition then
    doStuff
end
for iter = 0, 10 do
    doStuff
end

Mouse Buttons Integer Desigations

1 | LButton [FN2]
2 | MButton
3 | RButton
4 | XButton1
5 | XButton2

MISC FUNCTIONS

  • OnEvent(event, arg [, family]);
  • EnablePrimaryMouseButtonEvent(true|false);
  • PlayMacro("my macro");

MOVE MOUSE CURSOR/WHEEL

  • MoveMouseWheel(-1|1); -- mouse wheel [-1|1] click down
  • MoveMouseTo(0, 0); -- mouse to upper left corner
  • MoveMouseTo(32767, 32767); -- mouse to center screen
  • MoveMouseTo(65535, 65535); -- mouse to lower right corner
  • MoveMouseRelative(0, 0); -- move [dx, dy] relative to current position
  • MoveMouseToVirtual(0, 0); -- mouse to absolute position on multi-monitor layout

SET STATE

    SetBacklightColor((red, green, blue, [family]);
    SetMKeyState(mkey, [family]);
    SetMouseDPITable({value1, value2, value3}, [index]);
    SetMouseDPITable({500, 1000, 1500, 2000, 2500, ...16_entry_max})
    SetMouseDPITableIndex(1|2|3 ...16);
    Sleep( 20 );

GET STATE

-- ——————————————————————————————————————————————————————————————————————————————————————
    GetDate() • GetMousePosition() •  GetRunningTime() • GetKeyState() • GetMKeyState()
-- ——————————————————————————————————————————————————————————————————————————————————————

    date = GetDate([format [, time]])

    x, y = GetMousePosition()
    t_ms = GetRunningTime();

    "M1"|"M2"|"M3" = GetMKeyState(“kb”|"lhc")
    "M1"|"M2"|"M3" = GetMKeyState()

LOGGING & DEBUGGING

    OutputDebugMessage("logs to Windows debugger");
    OutputLCDMessage("logs to LCD");
    OutputLogMessage('logs to script editor');
    AbortMacro();
    ClearLog();

PRESS/RELEASE [mouse]

    PressAndReleaseMouseButton(1|2|3|4|5|6)
    PressMouseButton(1|2|3|4|5|6)
    ReleaseMouseButton(1|2|3|4|5|6)

PRESS/RELEASE [keyboard]

 -- keynames
    PressAndReleaseKey("a", "b", "c", ...)
    PressKey("a", "b", "c", ...)
    ReleaseKey("a", "b", ...)

 -- scancodes
    PressAndReleaseKey(1, 2, 4, ...)
    PressKey(1, 2, 3 ...)

BOOLEAN

    true|false = IsKeyLockOn();
    true|false = IsModifierPressed("lalt"|"ralt"|"alt")
    true|false = IsModifierPressed("lctrl", "rctrl", "ctrl"
    true|false = IsModifierPressed("lshift"|"rshift"|"shift")
    true|false = IsMouseButtonPressed( 1|2|3|4|5|6 )

OnEvent Function is mandatory.

    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

Press a mouse button:

    PressMouseButton(1)

    if IsMouseButtonPressed(1) then
      OutputLogMessage("Left mouse button is pressed.\n");
    end

Release a mouse button so that it is no longer pressed:

    ReleaseMouseButton(1)

    if not IsMouseButtonPressed(1) then
      OutputLogMessage("Left mouse button is not pressed.\n");
    end

Press a specific modifier:

    PressKey("lshift")

    if IsModifierPressed("shift") then
      OutputLogMessage("shift is pressed.\n");
    end

Release the key so it is no longer pressed:

    ReleaseKey("lshift")
    if not IsModifierPressed("shift") then
      OutputLogMessage("shift is not pressed.\n");
    end

Log current date/time:

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

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
String Functions
    string.byte
    string.char
    string.dump
    string.find
    string.format
    string.gmatch
    string.gsub
    string.len
    string.lower
    string.match
    string.rep
    string.reverse
    string.sub
    string.upper

Table Functions
    table.concat
    table.inserttable.maxn
    table.remove
    table.sort

Math Functions
    math.abs
    math.acos
    math.asin
    math.atan
    math.atan2
    math.ceil
    math.cos
    math.deg
    math.exp
    math.floor
    math.fmod
    math.frexp
    math.huge
    math.ldexp
    math.log
    math.log10
    math.max
    math.min
    math.modf
    math.pi
    math.pow
    math.rad
    math.random
    math.randomseed
    math.sin
    math.sinh
    math.sqrt
    math.tan
    math.tanh

FOOTNOTES

[FN1] The numbers on the left substitute for the mouse buttons on the right, when used as arguments for functions (e.g., PressMouseButton("MButton" 2)).
[FN2] LButton (1) not reported by default. Use EnablePrimaryMouseButtonEvents(true) to override.

About

Lua Cheatsheet for Logitech G Hub

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published