Skip to content

Instantly share code, notes, and snippets.

@jackrobertscott
Created July 19, 2023 06:00
Show Gist options
  • Save jackrobertscott/2da98b1c558baaf1687cb91a4f7424b0 to your computer and use it in GitHub Desktop.
Save jackrobertscott/2da98b1c558baaf1687cb91a4f7424b0 to your computer and use it in GitHub Desktop.
Mac gesture control using the Logitech G Hub software.
--[[
Usage: Logitech G HUB > Menu > Games & Applications > Profiles > Default > Scripting
Bottom button click: mission control.
Bottom button press & swipe left / right: go desktop left / right.
Bottom button press & swipe up / down: more mac menus...
Top button press: allows scrolling of left and right directions.
--]]
btnA = 4;
btnB = 5;
minMov = 100;
posStartX = 0;
posStartY = 0;
posEndX = 0;
posEndY = 0;
delay = 20
debug = false
function OnEvent(event, arg, family)
if arg == btnA then
-- button A
if event == "MOUSE_BUTTON_PRESSED" then
posStartX, posStartY = GetMousePosition()
elseif event == "MOUSE_BUTTON_RELEASED" then
posEndX, posEndY = GetMousePosition()
local difX = posEndX - posStartX
local difY = posEndY - posStartY
local absX = math.abs(difX)
local absY = math.abs(difY)
if debug then
OutputLogMessage(difX .. ":" .. difY .. "\n")
end
if absX < minMov and absY < minMov then
pressKeyCombo("lctrl", "up") -- app menu
elseif absX > absY then
-- horizontal
if difX > minMov then
-- right
pressKeyCombo("lctrl", "right") -- desktop left
elseif difX < -minMov then
-- left
pressKeyCombo("lctrl", "left") -- desktop left
end
else
-- vertical
if difY > minMov then
-- up
pressKeyCombo("lctrl", "up") -- app menu
elseif difY < -minMov then
-- down
pressKeyCombo("lctrl", "down") -- other app menu
end
end
end
elseif arg == btnB then
-- button B
if event == "MOUSE_BUTTON_PRESSED" then
PressKey("lshift")
elseif event == "MOUSE_BUTTON_RELEASED" then
ReleaseKey("lshift")
end
end
end
function pressKeyCombo(firstKey, secondKey)
if debug then
OutputLogMessage(firstKey .. ":" .. secondKey .. "\n")
end
PressKey(firstKey)
PressKey(secondKey)
Sleep(delay)
ReleaseKey(firstKey)
ReleaseKey(secondKey)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment