Elegant Autohotkey winkey simulation for WKL vintage / customs

User avatar
Keybug

07 Nov 2018, 09:41

Came up with the following code for a hotkey. What it does is set up the ISO caret / ANSI tilde key (the one normally found right down from the escape key) as a fully functional windows key unless you double press it quickly, in which case it will send the actual character mapped to that key. I've only tested this with ISO mapping so it may not work without some slight modifications on an ANSI system. Also, this is meant for Windows 10 and would need adapting for earlier versions of the OS.

Here's hoping this may be useful for some of youse. I really like that location for the winkey, as many frequent combinations are quite easy to do with one hand, e.g. Win + e / r / x / low numbers.

More specifically I have included one example of a custom combination not usually used by Windows, i.e. when I press that key in combination with Capslock, it will shut down my computer.

Any feedback appreciated!

Code: Select all

$SC029:: ; downstroke!
	if (WinActive("Cortana")) ; do nothing on downstroke if the start menu is active (usually this is the downstroke on the second press for double press intended to send the caret / tilde character)
		return
	Suspend ; on any other downstroke, these three lines prepare to read the key that is to be combined with the windows key as a modifier
	Input, ZirkumCombo, I L1 T0.8, {CapsLock}, abcdefghijklmnopqrstuvwxyz1234567890
	ErrLvl := ErrorLevel
return

$SC029 Up:: ; upstroke
	Suspend Off
	if (WinActive("Cortana")) { ; on the upstroke of a double press, close the start menu and send the key's original character
		Send {Escape}
		sleep 100
		Send {SC029}
		return
	}

	if (ErrLvl = "EndKey:CapsLock") { ; example of how to use non-alphanumeric keys for special combos - these also have to be listed in the 'Input' statement above
		Send {Capslock} ; make sure Caps is not locked
		SetCapsLockState Off ; same as above - to make doubly sure
		Shutdown, 8 ; shutdown Windows - useful?
		return
	 }

		Send {LWin Down}%ZirkumCombo%{LWin Up} ; send the combination of Win + your chosen combo key to the OS
		ZirkumCombo := "" ; empty the Input variable to allow a single press of the key to show the start menu
return

Post Reply

Return to “Keyboards”