Logi Nu
Posts: 4
Registered: ‎11-07-2013

Toggle and/or Hold script for custom keys

[ Edited ]

Hi every one,

been looking all over the place for a script that can toggle key-combos on and off and at the same time have other keys have key-combos that will only work if you keep the G-Key pressed down. But i couldn't find any, so i wrote my own script for it and made it user friendly so i could share it with you. (And yes it was created with minecraft and DayZ in mind, finally auto walk!)


Hope you like it, and please give feedback if you use it Smiley Happy


Added on pastebin due to problems with text formatting on this forum in code form

Logi Nu
Posts: 4
Registered: ‎11-07-2013

Re: Toggle and Hold script for custom keys

New Link!
Script updated with som rearrange of code and a small description typo fix

Logi Nu
Posts: 4
Registered: ‎11-07-2013

Re: Toggle and Hold script for custom keys

Script Updated! (same link)

- rewrote toggle function to simplify routine

- created proper LCD Draw function

- updated check function so it will now display on LCD if a key isn't configured or not in key array and will not switch state in toggle mode if not configured



todo list:
- able to choose between "lhc" (G13) and "kb"(G-series keyboards) as an array option
- able to set color of "lhc" or "kb" if a key is toggled or pressed down

Logi Master
Posts: 3,139
Registered: ‎06-04-2010

Re: Toggle and Hold script for custom keys

[ Edited ]

You may find what you are doing to be a lot of fun, which I did as well, but you may also be interested in the ways others have advanced their scripts.  Here is a script system I created.  The basic table system here was inspired by something kgober showed with his script system.


 Sample of my Dragon Age script:

-- llProject End -->
ll=ll or {}; ll.SETUP = { Folder = [[E:\Logitech Scripts\llProject\]] }
dofile(ll.SETUP.Folder .. [[llProject.lua]])
-- llProject End -->, 0, 255)

-- ll.devMode = dm_TEST

function _OnActivation()[0] = {
		G4 = "r",	
		G5 = { fn_toggle, "tab" },		-- toggle Highlight Objects
		G6 = "lshift",
		G8 = "f9",					-- Quick Load
		G10 = "f5",					-- Quick Save
	}[0] = {
		G26 = "w",
		G27 = "d",
		G28 = "s",
		G29 = "a",
	}[1] = {
		G1 = "n",						-- World Map
		G2 = "1",	
		G3 = "2",
		G4 = "3",
		G5 = "4",	
		G6 = "5",	
		G7 = { fn_mod_keystroke, {"lctrl"}, "a", 10},		-- Select Party

		G8 =  "m",					-- Map
		G9 =  "6",	
		G10 = "7",
		G11 = "8",
		G12 = "9",	
		G13 = "0",
		G14 = "h",					-- Hold Position

		G15 = "i",					-- Inventory
		G16 = "c",					-- Character Record
		G17 = "k",					-- Skills
		G18 = "p",					-- Spells & Talents
		G19 = "j",					-- Journal

		G20 = "backslash",				-- Tactics
		G21 = "numslash",				-- Run/Walk Toggle
		G22 = "slash",				-- Weapon Swap

		G23 = "escape",
		G24 = "spacebar",				-- pause
	} = {
		G3 = "f1",					-- Select Party Member 1
		G4 = "f2",					-- Select Party Member 2
		G5 = "f3",					-- Select Party Member 3
		G6 = "f4",					-- Select Party Member 4

-- eof


The tables created, are a map of keystrokes.[1]  -- is a table for the left handed controller (G13) on MState 1.[0]  -- is a table for the mouse on all MStates (0 is for all M states, 1 is for MState 1, 2 is for Mstate 2 ...)  -- is a table for the G13 when the mouse button 7 is pressed.  This is one way to create custom M states.[0] -- would be for the keyboard on any M state.


Assigning a G key directly to a string, treats it as a keystroke macro, which is the same as your hold until released script.

You can also assign it to special functions within a table, such as fn_toggle(), which will toggle the key given to it.


I also have systems in place to run functions continuously in the background.  Something not normal possible without exploiting some of the functions given by logitech.

Posts: 6,511
Kudos: 921
Solutions: 537
Registered: ‎05-28-2009

Re: Toggle and Hold script for custom keys

I don't usually use toggle keys, but in some games they're useful.  I'm pretty sure I've posted toggle scripts in the past, if not in this forum then the G-series Mouse forum.



I do not work for Logitech. I'm just a user.