├── LICENSE
├── README.md
├── code.lua
├── code.multi.lua
├── docs
├── APIDocs.pdf
├── generator.html
├── generator.js
├── index.html
├── io.js
├── tutorial.html
└── tutorial_images
│ ├── copy.JPG
│ ├── saved.JPG
│ ├── scripting.JPG
│ └── unsaved.JPG
├── mouse.lua
├── template.lua
└── template.lua.b64
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Tom
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Toggle buttons using Logitech gaming software
2 |
3 | [](https://app.codacy.com/app/tom.k.hipwell/logitech-toggle-keys?utm_source=github.com&utm_medium=referral&utm_content=Douile/logitech-toggle-keys&utm_campaign=Badge_Grade_Dashboard)
4 |
5 | _Version 8.97.88_
6 |
7 | _LUA API Version 8.45_
8 |
9 | ---
10 |
11 | The code below can be used in the script section of profiles in logitech gaming software to toggle pressing keys.
12 |
13 | **Enjoy!**
14 |
15 | [code](/code.lua)
16 |
17 | [generator](https://douile.github.io/logitech-toggle-keys/generator.html)
18 |
--------------------------------------------------------------------------------
/code.lua:
--------------------------------------------------------------------------------
1 | -- choose your keys here
2 | -- e.g. if I wanted button 1 to toggle e I would put {e=1};
3 | -- e.g. if I wanted button 3 to toggle e I would put {e=3,f=3,g=2};
4 | keysetup = {f={5,2},a={4,0}};
5 | -- if using mouse set to true
6 | mouse = false;
7 | -- set to true to log all button presses (useful when you don't know what number a key is)
8 | logall = true;
9 | -- change the delay between taps
10 | tap_delay = 30;
11 | tap_hold_delay = 5;
12 |
13 | -- do not change the code below
14 | OutputLogMessage("Script initialized\nWritten by: Douile\n");
15 | if (mouse == true) then
16 | eventlisten = "MOUSE_BUTTON_PRESSED";
17 | OutputLogMessage("Configured for mouse buttons\n");
18 | else
19 | eventlisten = "G_PRESSED";
20 | OutputLogMessage("Configured for keyboard buttons\n");
21 | end
22 | for k,v in pairs(keysetup) do
23 | OutputLogMessage("Button %d will toggle %s (%d presses)\n",v[1],k,v[2]);
24 | end
25 | OutputLogMessage("\n- start runtime log -\n");
26 |
27 | keyspressed = {};
28 |
29 | function OnEvent(event, arg)
30 | if (event == eventlisten) then
31 | if (logall == true) then
32 | OutputLogMessage("Key %d pressed\n",arg);
33 | end
34 | for k,v in pairs(keysetup) do
35 | if (arg == v[1] and k ~= null) then
36 | if (keyspressed[k] == true) then
37 | ReleaseKey(k);
38 | keyspressed[k] = false;
39 | OutputLogMessage("Recieved %s %d released %s\n",event,v[1],k);
40 | OutputLCDMessage(string.format("Pressing %s",k));
41 | else
42 | for i=0,v[2] do
43 | PressKey(k);
44 | Sleep(tap_hold_delay);
45 | ReleaseKey(k);
46 | Sleep(tap_delay);
47 | end
48 | PressKey(k);
49 | keyspressed[k] = true;
50 | OutputLogMessage("Recieved %s %d pressed %s\n",event,v[1],k);
51 | OutputLCDMessage(string.format("Releasing %s",k));
52 | end
53 | end
54 | end
55 | end
56 | end
57 |
--------------------------------------------------------------------------------
/code.multi.lua:
--------------------------------------------------------------------------------
1 | -- keysetup format for each key:
2 | -- {event_register,event_number,{args...},{actions...}}
3 | -- args -> hash map
4 | -- actions -> array -> hash-map (key "action" always set to action name and key "key" always set to the name of the key to press)
5 | -- remember arrays are 1 based not 0 based in lua
6 |
7 | keysetup = {{"G_PRESSED",4,{},{{action="toggle_key",key="f"},{action="tap_key",key="x",count=3,duration=30,delay=20}}},{"TIMED",5,{time=1500,event_prefix="G"},{{{action="toggle_key",key="a"}},{{action="toggle_key",key="b"}}}}};
8 |
9 | logging = true;
10 |
11 | -- do not change the code below
12 | OutputLogMessage("Script initialized\nWritten by: Douile\nhttps://github.com/Douile/logitech-toggle-keys/\n");
13 | for i,v in pairs(keysetup) do
14 | OutputLogMessage("%s:%d registered...\n",v[1],v[2]);
15 | end
16 | OutputLogMessage("\n- start runtime log -\n");
17 |
18 | keyspressed = {};
19 | keytimes = {};
20 |
21 | function update_key(key,state)
22 | if (state == true) then
23 | PressKey(key);
24 | keyspressed[key] = true;
25 | word = "Pressed";
26 | else
27 | ReleaseKey(key);
28 | keyspressed[key] = nil;
29 | word = "Released"
30 | end
31 | if (logging == true) then
32 | OutputLogMessage("+%d - %s %s\n",GetRunningTime(),word,key);
33 | end
34 | end
35 |
36 | function handle_custom_events(setup_info,event,arg)
37 | -- handle custom listeners such as G keys held
38 | if (setup_info[1] == "TIMED") then
39 | prefix = setup_info[3]["event_prefix"];
40 | if (event == prefix.."_PRESSED" and setup_info[2] == arg) then
41 | id = string.format("%s_%d",prefix,arg);
42 | keytimes[id] = GetRunningTime();
43 | if (logging == true) then
44 | OutputLogMessage("+%d - Starting holding %s\n",GetRunningTime(),id);
45 | end
46 | elseif (event == prefix.."_RELEASED" and setup_info[2] == arg) then
47 | id = string.format("%s_%d",prefix,arg);
48 | time_held = GetRunningTime()-keytimes[id];
49 | keytimes[id] = nil;
50 | -- possibly add support for multiple time ranges of time held
51 | if (time_held < setup_info[3]["time"]) then
52 | dispatch_actions(setup_info[3],setup_info[4][1]);
53 | else
54 | dispatch_actions(setup_info[3],setup_info[4][2]);
55 | end
56 | end
57 | return true;
58 | end
59 | return false;
60 | end
61 |
62 | function dispatch_actions(args,actions)
63 | for i,action in pairs(actions) do
64 | v = action["action"];
65 | key = action["key"];
66 | if (v == "toggle_key") then
67 | if (keyspressed[key] == true) then
68 | update_key(key,false);
69 | else
70 | update_key(key,true);
71 | end
72 | elseif (v == "press_key") then
73 | update_key(key,true);
74 | elseif (v == "release_key") then
75 | update_key(key,false);
76 | elseif (v == "tap_key") then
77 | for n=0,action["count"],1 do
78 | PressKey(key);
79 | Sleep(action["duration"]);
80 | ReleaseKey(key);
81 | Sleep(action["delay"]);
82 | end
83 | end
84 | end
85 | end
86 |
87 | function OnEvent(event, arg)
88 | for i,v in pairs(keysetup) do
89 | did_custom = handle_custom_events(v,event,arg);
90 | if (did_custom == false) then -- (not did_custom)
91 | if (event == v[1] and arg == v[2]) then
92 | dispatch_actions(v[3],v[4]);
93 | end
94 | end
95 | end
96 | end
97 |
--------------------------------------------------------------------------------
/docs/APIDocs.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Douile/logitech-toggle-keys/46a845003a6c6168b97d4f2d30e513e71c5977cb/docs/APIDocs.pdf
--------------------------------------------------------------------------------
/docs/generator.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |