Skip to content

Instantly share code, notes, and snippets.

@jpuskar
Created June 18, 2018 02:11
Show Gist options
  • Save jpuskar/6bb9014b543fcd7f666505dd302b4817 to your computer and use it in GitHub Desktop.
Save jpuskar/6bb9014b543fcd7f666505dd302b4817 to your computer and use it in GitHub Desktop.
--[[
This allows you to bind any function-number key (F1-F24) to a "G" button on your mouse.
To add a binding, insert a new element in the bindings table below and save this script.
Script by tgp1994 (https://github.com/tgp1994)
]]
local bindings = {
G5 = "F13"
}
local function bind_mouseDown(arg)
for k,v in pairs(bindings) do
if k == arg then
local bindGroup = string.sub(v, 1, 1)
if bindGroup == "F" then
local fKey = string.sub(v, 2)
--OutputLogMessage("Pressing button F%s.\n", fKey)
PressKey(88 + fKey)
else
OutputLogMessage("Mouse button '%s' has an unrecognized binding '%s'.\n", k, v)
end
end
end
end
local function bind_mouseUp(arg)
for k,v in pairs(bindings) do
if k == arg then
local bindGroup = string.sub(v, 1, 1)
if bindGroup == "F" then
--OutputLogMessage("Key up.\n")
local fKey = string.sub(v, 2)
ReleaseKey(88 + fKey)
end
end
end
end
function OnEvent(event, arg)
--OutputLogMessage("event = %s, arg = %s\n", event, arg)
if event == "MOUSE_BUTTON_PRESSED" then
bind_mouseDown("G"..arg)
elseif event == "MOUSE_BUTTON_RELEASED" then
bind_mouseUp("G"..arg)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment