Advertisement
GeekGarage

Logitech G-Series Keyboard script

Nov 8th, 2013
906
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.06 KB | None | 0 0
  1. --[[
  2. This script is made by GeekGarage aka. xibit1987
  3. Created for G19, but will work on other G-Series hardware
  4.  
  5. Guide on how to use:
  6. {["key"]=12, ["state"]=false, ["type"]="t", ["keys"]={"rctrl", "lshift", "s"}, ["mouse"]=1, ["lcdText"]={"Text Here", "and you", "can use up to 8 lines on G19", "and 3 lines on others"}}
  7.  
  8. "key" is the G-Key number, for now it's not in use and is only there to keep an overview of the array so it's easy to see what key you are editing
  9. "state" DO NOT TOUCH! Used to check state in toggle type mode
  10. "type" is Toggle type key [t] or Hold/keep pressed down type of key [h]
  11. "keys" are what keys to emulate pressed, always add modifiers first like "lshift", "rshift", "lctrl", since it will be pressed in the order they are added (Look at example above). Default if not in use is    ["keys"]={nil}
  12. "mouse" is what mouse button to press (can only handle a single button. Default if not in use   ["mouse"]=nil
  13. "lcdText" is the text you want to display. each section ["Text Here"] is a new line. The display can show up to 9 lines, but the last line is used to show if key is toggled or pressed down
  14.  
  15. Remember if you add a line ONLY the last one is without "," at the end. Same if you delete some of the keys, remember to remove "," at the last one
  16.  
  17. this is a default line for a key not in use:
  18. {["key"]=1, ["state"]=false, ["type"]="t", ["keys"]={nil}, ["mouse"]=nil, ["lcdText"]={nil}}
  19.  
  20. ]]--
  21. --if used on a gaming series without display set to false
  22. enableLCD = true
  23. lcdMessageTimeout = 5000 --in ms
  24.  
  25. --Set up G-Keys Here--
  26. gKey = {
  27.     {["key"]=1, ["state"]=false, ["type"]="h", ["keys"]={nil}, ["mouse"]=nil, ["lcdText"]={nil}},
  28.     {["key"]=2, ["state"]=false, ["type"]="h", ["keys"]={nil}, ["mouse"]=nil, ["lcdText"]={nil}},
  29.     {["key"]=3, ["state"]=false, ["type"]="h", ["keys"]={nil}, ["mouse"]=nil, ["lcdText"]={nil}},
  30.     {["key"]=4, ["state"]=false, ["type"]="h", ["keys"]={nil}, ["mouse"]=nil, ["lcdText"]={nil}},
  31.     {["key"]=5, ["state"]=false, ["type"]="h", ["keys"]={nil}, ["mouse"]=nil, ["lcdText"]={nil}},
  32.     {["key"]=6, ["state"]=false, ["type"]="h", ["keys"]={nil}, ["mouse"]=nil, ["lcdText"]={nil}},
  33.     {["key"]=7, ["state"]=false, ["type"]="t", ["keys"]={nil}, ["mouse"]=nil, ["lcdText"]={nil}},
  34.     {["key"]=8, ["state"]=false, ["type"]="t", ["keys"]={nil}, ["mouse"]=nil, ["lcdText"]={nil}},
  35.     {["key"]=9, ["state"]=false, ["type"]="t", ["keys"]={nil}, ["mouse"]=nil, ["lcdText"]={nil}},
  36.     {["key"]=10, ["state"]=false, ["type"]="t", ["keys"]={nil}, ["mouse"]=nil, ["lcdText"]={nil}},
  37.     {["key"]=11, ["state"]=false, ["type"]="t", ["keys"]={nil}, ["mouse"]=nil, ["lcdText"]={nil}},
  38.     {["key"]=12, ["state"]=false, ["type"]="t", ["keys"]={nil}, ["mouse"]=nil, ["lcdText"]={nil}}
  39. }
  40.  
  41. --DO NOT EDIT BELOW THIS LINE
  42. function toggleState(arg)
  43.     if gKey[arg]["keys"][1] == nil and gKey[arg]["mouse"] == nil then
  44.         drawLCD("empty", arg)
  45.     else
  46.         OutputLCDMessage(gKey[arg]["keys"], lcdMessageTimeout)
  47.         if not gKey[arg]["state"] then
  48.             drawLCD("tOn", arg)
  49.             for k,v in pairs(gKey[arg]["keys"]) do
  50.                 PressKey(v);
  51.             end
  52.             Sleep(50);
  53.             if gKey[arg]["mouse"] ~= nil then
  54.                 PressMouseButton(gKey[arg]["mouse"]);
  55.             end
  56.             gKey[arg]["state"] =  true
  57.         else
  58.             drawLCD("tOff", arg)
  59.             for k,v in pairs(gKey[arg]["keys"]) do
  60.                 ReleaseKey(v);
  61.             end
  62.    
  63.             if gKey[arg]["mouse"] ~= nil then
  64.                 ReleaseMouseButton(gKey[arg]["mouse"]);
  65.             end
  66.             gKey[arg]["state"] = false
  67.         end
  68.     end
  69. end
  70.  
  71.  
  72. function holdState(event, arg)
  73.     if event == "G_PRESSED" then
  74.         drawLCD("hOn", arg)
  75.         for k,v in pairs(gKey[arg]["keys"]) do
  76.             PressKey(v);
  77.         end
  78.         Sleep(50);
  79.         if gKey[arg]["mouse"] ~= nil then
  80.             PressMouseButton(gKey[arg]["mouse"]);
  81.         end
  82.     end
  83.     if event == "G_RELEASED" then
  84.         drawLCD("hOff", arg)
  85.         for k,v in pairs(gKey[arg]["keys"]) do
  86.             ReleaseKey(v);
  87.         end
  88.         Sleep(50);
  89.         if gKey[arg]["mouse"] ~= nil then
  90.             ReleaseMouseButton(gKey[arg]["mouse"]);
  91.         end
  92.     end
  93. end
  94.  
  95.  
  96. function drawLCD(_lineToWrite, arg)
  97.     if enableLCD then
  98.         ClearLCD()
  99.         if _lineToWrite == "nArray" then
  100.             _messageToWrite = "Key Not In Array"
  101.         elseif gKey[arg]["keys"][1] == nil and gKey[arg]["mouse"] == nil then
  102.             _messageToWrite = "Key Not Configured"
  103.         else
  104.             for k,v in pairs(gKey[arg]["lcdText"]) do
  105.                 OutputLCDMessage(v, lcdMessageTimeout)
  106.             end
  107.             if _lineToWrite == "tOn" then
  108.                 _messageToWrite = "Key Toggled ON"
  109.             elseif _lineToWrite == "tOff" then
  110.                 _messageToWrite = "Key Toggled OFF"
  111.             elseif _lineToWrite == "hOn" then
  112.                 _messageToWrite = "Key Hold ON"
  113.             elseif _lineToWrite == "hOff" then
  114.                 _messageToWrite = "Key Hold OFF"
  115.             end
  116.         end
  117.         OutputLCDMessage(_messageToWrite, lcdMessageTimeout)
  118.     end
  119. end
  120.  
  121.  
  122. function OnEvent(event, arg)
  123.     if event == "G_PRESSED" then
  124.         if arg >= 1 and arg <= tonumber(#gKey) then
  125.             if gKey[arg]["type"] == "t" then
  126.                 toggleState(arg)
  127.             elseif gKey[arg]["type"] == "h" then
  128.                 holdState(event, arg)
  129.             end
  130.         else
  131.             drawLCD("nArray", arg)
  132.         end
  133.     elseif event == "G_RELEASED" then
  134.         if arg >= 1 and arg <= tonumber(#gKey) then
  135.             if gKey[arg]["type"] == "h" then
  136.                 holdState(event, arg)
  137.             end
  138.         end
  139.     end
  140. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement