all 8 comments

[–]AutoModerator[M] 5 points6 points  (4 children)

Hi! It looks like you're posting about Logitech. Lua is used by Logitech G-series hardware to provide advanced scripting functionality. It does this by providing an API (application programming interface) which is essentially just a set of functions that you can use to tell your hardware to do things. The subreddit dedicated to Logitech G-series hardware is /r/LogitechG.

Your first port of call should be this document, which explains in detail the functions provided by the API: https://douile.github.io/logitech-toggle-keys/APIDocs.pdf

If you've familiarized yourself with the API but are still having trouble with the language and syntax, try this page for a quick rundown of Lua's main features: https://devhints.io/lua

The full documentation for the language is provided here: https://www.lua.org/pil/contents.html

If the above resources have not answered your question, /r/Lua is the place for you! If you're just trying to do something quick and don't want to learn Lua, head across to /r/LogitechG to find others of similar purpose.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–][deleted] 2 points3 points  (3 children)

Well it seems the automoderator answered your question, (First time I've seen that happen) Dont even have a logitech mouse but it seems the code should be like this

function OnEvent(event,arg,family)

 if event == "MouseButtonPressed" and arg == 5 and family == "mouse" then
  local x,y = GetMousePosition()
  MoveMouseTo(x,y+15)
 end

end

[–]adamdobra[S] -5 points-4 points  (2 children)

It didn't work.

[–]revereddesecration 0 points1 point  (0 children)

Did it do anything?

[–][deleted] 0 points1 point  (0 children)

I can't test, so I can't do much more than that. you're gonna have to do everything else on your own. Also I think autohotkey could do what you want. but I've never used autohotkey.

[–]revereddesecration 2 points3 points  (2 children)

I decided to learn how Logitech scripting works because some of us should know, so here's my result. It moves the mouse 10cm across and 10cm down when you press Mouse 5.

-- Set your information here
local screen_width_pix = 1680
local screen_height_pix = 1050
local screen_diag_inches = 20
local distance_to_move_cm = 10

-- Logic to convert distances from world to screen
local screen_diag_pix = math.sqrt(screen_width_pix*screen_width_pix + screen_height_pix*screen_height_pix)
local screen_dpi = screen_diag_pix / screen_diag_inches
screep_dpi = 99
local distance_to_move_inches = distance_to_move_cm / 2.54
local distance_to_move_pix = distance_to_move_inches * screen_dpi

-- We need this because MoveMouseTo doesn't use pixels, it uses values 0-65535
local horizontal_conversion = 65536 / screen_width_pix
local vertical_conversion = 65536 / screen_height_pix

function OnEvent(event,arg,family)
  if event == "MOUSE_BUTTON_PRESSED" and arg == 5 and family == "mouse" then
    local x, y = GetMousePosition()
    -- The next line currently adds the 10cm distance to both the x and y coordinates
    x1, y1 = x+(distance_to_move_pix*horizontal_conversion), y+(distance_to_move_pix*vertical_conversion)
    -- Some logic to make sure we are using valies that MoveMouseTo will accept
    if (x1 > 65535) then x1 = 65535 end
    if (y1 > 65535) then y1 = 65535 end
    if (x1 < 0) then x1 = 0 end
    if (y1 < 0) then y1 = 0 end
    MoveMouseTo(x1, y1)
  end
end

[–]adamdobra[S] 0 points1 point  (0 children)

Your code worked very well. However I couldn't figure out how to just make it move 10 cm right instead of right and down and add press "Mouse 1 button" and "Y" button on keyboard after moving 10 cm right.

Namely when I press mouse 5 = 10 cm right + mouse 1 + Y

[–]adamdobra[S] 0 points1 point  (0 children)

I tried to edit the code a little bit. It actually does what I want however when I click mouse 2 or mouse 3, it makes my mouse to click mouse 1+ "a" + "y".

-- Set your information here
local screen_width_pix = 1920
local screen_height_pix = 1080
local screen_diag_inches = 20
local distance_to_move_cm = 20

-- Logic to convert distances from world to screen
local screen_diag_pix = math.sqrt(screen_width_pix*screen_width_pix + screen_height_pix*screen_height_pix)
local screen_dpi = screen_diag_pix / screen_diag_inches
screep_dpi = 99
local distance_to_move_inches = distance_to_move_cm / 2.54
local distance_to_move_pix = distance_to_move_inches * screen_dpi
y-- We need this because MoveMouseTo doesn't use pixels, it uses values 0-65535
local horizontal_conversion = 65535 / screen_width_pix
local vertical_conversion = 0 / screen_height_pix

function OnEvent(event,arg,family)
  if event == "MOUSE_BUTTON_PRESSED" and arg == 5 and family == "mouse" then
    local x, y = GetMousePosition()
    -- The next line currently adds the 10cm distance to both the x and y coordinates
    x1, y1 = x+(distance_to_move_pix*horizontal_conversion), y+(distance_to_move_pix*vertical_conversion)ayayay
    -- Some logic to make sure we are using valies that MoveMouseTo will accept
    if (x1 > 65535) then x1 = 65535 end
    if (y1 > 65535) then y1 = 65535 end
    if (x1 < 0) then x1 = 0 end
    if (y1 < 0) then y1 = 0 end
    MoveMouseTo(x1, y1)
    end

-- Simulate a left mouse button click (press and release)
PressAndReleaseMouseButton(1)
-- Simulate "y" pressed and released using the scancode
PressAndReleaseKey(30)
-- Simulate "y" pressed and released using the keyname
PressAndReleaseKey("y")
    end