Simplifying Remapped Custom Combinations

Get help with using AutoHotkey and its commands and hotkeys
WalterRoberts
Posts: 41
Joined: 25 Feb 2020, 20:00

Simplifying Remapped Custom Combinations

09 May 2020, 12:29

This code works flawlessly by turning Numpad0 in a Control modifier key and NumpadDot in a Shift modifier key when working with the Numpad Keys. It even makes it possible to use Numpad0 & NumpadDot in conjunction to gain a Control+Shift modification (if the keyboard rollover has a high enough count).
But most importantly this specific syntax does not destroy the native function of the Numpad0 key itself and moreover it is also still possible to press LControl+Numpad0.
The only known limitation is the disabled software repetition function for the prefix keys, which I personally do not need.
All original credit goes to the author of this thread: https://autohotkey.com/board/topic/83755-using-an-arbitrary-key-as-a-modifier-without-sacrificing-it/

Code: Select all

#singleinstance, force
Pause::Suspend
~^s::reload

numpad0 & F1::Return ; Make the release of Numpad0 produce a Numpad0 keystroke.
*numpad0::Send {Blind}{numpad0} ; Send it explicitly when no other key is pressed before letting go, including any modifiers being held

#If GetKeyState("numpad0", "p")
{
	;Control+NumpadN
	$numpad1::Send {Ctrl down}{numpad1}{Ctrl up}
	$numpad2::Send {Ctrl down}{numpad2}{Ctrl up}
	$numpad3::Send {Ctrl down}{numpad3}{Ctrl up}
	$numpad4::Send {Ctrl down}{numpad4}{Ctrl up}
	$numpad5::Send {Ctrl down}{numpad5}{Ctrl up}
	$numpad6::Send {Ctrl down}{numpad6}{Ctrl up}
	$numpad7::Send {Ctrl down}{numpad7}{Ctrl up}
	$numpad8::Send {Ctrl down}{numpad8}{Ctrl up}
	$numpad9::Send {Ctrl down}{numpad9}{Ctrl up}
	$NumpadAdd::Send {Ctrl down}{NumpadAdd}{Ctrl up}
	$NumpadSub::Send {Ctrl down}{NumpadSub}{Ctrl up}
	
	NumpadDot::Return ;avoiding collision with Numpad0

		;Control+Shift+NumpadN
		NumpadDot & numpad1::Send {Ctrl down}{Shift down}{numpad1}{Shift up}{Ctrl up}
		NumpadDot & numpad2::Send {Ctrl down}{Shift down}{numpad2}{Shift up}{Ctrl up}
		NumpadDot & numpad3::Send {Ctrl down}{Shift down}{numpad3}{Shift up}{Ctrl up}
		NumpadDot & numpad4::Send {Ctrl down}{Shift down}{numpad4}{Shift up}{Ctrl up}
		NumpadDot & numpad5::Send {Ctrl down}{Shift down}{numpad5}{Shift up}{Ctrl up}
		NumpadDot & numpad6::Send {Ctrl down}{Shift down}{numpad6}{Shift up}{Ctrl up}
		NumpadDot & numpad7::Send {Ctrl down}{Shift down}{numpad7}{Shift up}{Ctrl up}
		NumpadDot & numpad8::Send {Ctrl down}{Shift down}{numpad8}{Shift up}{Ctrl up}
		NumpadDot & numpad9::Send {Ctrl down}{Shift down}{numpad9}{Shift up}{Ctrl up}
}
#If

NumpadDot & F1::Return
*NumpadDot::Send {Blind}{NumpadDot}

#If GetKeyState("NumpadDot", "p")
{	
	;Shift+NumpadN
	$numpad1::Send {Shift down}{numpad1}{Shift up}
	$numpad2::Send {Shift down}{numpad2}{Shift up}
	$numpad3::Send {Shift down}{numpad3}{Shift up}
	$numpad4::Send {Shift down}{numpad4}{Shift up}
	$numpad5::Send {Shift down}{numpad5}{Shift up}
	$numpad6::Send {Shift down}{numpad6}{Shift up}
	$numpad7::Send {Shift down}{numpad7}{Shift up}
	$numpad8::Send {Shift down}{numpad8}{Shift up}
	$numpad9::Send {Shift down}{numpad9}{Shift up}
	$NumpadAdd::Send {Shift down}{NumpadAdd}{Shift up}
	$NumpadSub::Send {Shift down}{NumpadSub}{Shift up}

	Numpad0::Return ;avoiding collision with NumpadDot
}
#If

I am now looking for a way to simplify this code for further implementations. I want to repeat all of this with NumpadEnter and other keys for example.
Also I am thinking about applying this to the {Space} key to get something like Control+[pressed key] or Shift+[pressed key] maybe. I am imagining there must be a more simple way to achieve this (at least when always using the same modification) than to write out all combinations like so:

Code: Select all

Space & F1::Return
*Space::Send {Blind}{Space}
#If GetKeyState("Space", "p")
{	q::Send {Ctrl down}{q}{Ctrl up}
	w::Send {Ctrl down}{w}{Ctrl up}
	e::Send {Ctrl down}{e}{Ctrl up}
	r::Send {Ctrl down}{r}{Ctrl up}
	t::Send {Ctrl down}{t}{Ctrl up}
	y::Send {Ctrl down}{y}{Ctrl up}
	;and so on for all common keys
}
#If
I want to emphasize though that this syntax is the only one I have found to work without any unwanted limitations.
GEV
Posts: 844
Joined: 25 Feb 2014, 00:50

Re: Simplifying Remapped Custom Combinations

09 May 2020, 13:44

Code: Select all

Space::Control                      ; bind Space to be Control

Space Up::
    Send, {Ctrl up}             	; release the Control key
    If GetKeyState("LShift","P") 	; LShift+Space
        MsgBox, LShift+Space
	else
    If GetKeyState("Alt","P") 		; Alt+Space
        MsgBox, Alt+Space
    else
    If (A_PriorKey = "Space")       ; Space was pressed alone
        Send, {Space}
return
WalterRoberts
Posts: 41
Joined: 25 Feb 2020, 20:00

Re: Simplifying Remapped Custom Combinations

22 May 2020, 15:44

@GEV You absolutely had the right idea and helped me create an (almost) fully working solution. The specific problem I was having with your code was not any longer being able to use LWin+Space for example to change input language - in other words all combinations with {Modifier}+{Space} would no longer come through...

I have been able to remedy this shortcoming by kind of merging the best of both syntaxes:

Code: Select all

*Space::
Send, {Ctrl Down}
KeyWait, Space
If (A_PriorKey = "Space") {
	Send, {Ctrl Up}
	Send, {Blind}{Space}
}
Else 
	Send, {Ctrl Up}
return

The only known problem still remaining is that "A_PriorKey" will neither recognize MouseWheel nor LButton, so {Space} will still be sent, when for instance using Space+MouseWheel (which is actually Ctrl+MouseWheel). Is it possible to avoid sending {Space} when in the meantime either WheelUp/Down or LButton were pressed?

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], BranW, Epialis, frankr, Google [Bot], imNotTupid, ReCordLe, Smile_ and 51 guests