Reply
Logi Nu
GeekGarage
Posts: 3
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 :smileyhappy:

 

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

http://pastebin.com/xxi35c6p

Logi Nu
GeekGarage
Posts: 3
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
GeekGarage
Posts: 3
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 Guru
bystander
Posts: 1,883
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.

 

http://upia.de/g-forum/viewtopic.php?f=9&t=84&sid=2e42885e3ff384e127530ed21428d86b

 

 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 -->
ll.lhc.map.mb7:SetBacklightColor(0, 0, 255)

-- ll.devMode = dm_TEST

function _OnActivation()
	ll.mouse.map[0] = {
		G4 = "r",	
		G5 = { fn_toggle, "tab" },		-- toggle Highlight Objects
		G6 = "lshift",
		G8 = "f9",					-- Quick Load
		G10 = "f5",					-- Quick Save
	}
	ll.lhc.map[0] = {
		G26 = "w",
		G27 = "d",
		G28 = "s",
		G29 = "a",
	}
	ll.lhc.map[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
	}
	ll.lhc.map.mb7 = {
		G3 = "f1",					-- Select Party Member 1
		G4 = "f2",					-- Select Party Member 2
		G5 = "f3",					-- Select Party Member 3
		G6 = "f4",					-- Select Party Member 4
	}
end

-- eof

 

The tables created, are a map of keystrokes. 

ll.lhc.map[1]  -- is a table for the left handed controller (G13) on MState 1.

ll.mouse.map[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 ...)

ll.lhc.map.mb7  -- is a table for the G13 when the mouse button 7 is pressed.  This is one way to create custom M states.

ll.kb.map[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.

kgober
Posts: 5,748
Kudos: 779
Solutions: 474
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.

 

-ken

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