Remap Win key when it's pressed alone Topic is solved
Remap Win key when it's pressed alone
Hello, I'm new to AHK and I'm stucked at a probably very simple problem. I want to remap Win to Ctrl + Home only if Win is pressed alone and other Win shortcuts (Win+Tab, Ctrl+Win+→, etc.) should not be affected. I tried the solution in this thread, it sends Ctrl+Home when press Win alone, but it also makes the start menu pops up...
Could someone please help? I'm using V2 but I won't mind switching back if V1 code is given. Thanks in advance.
Could someone please help? I'm using V2 but I won't mind switching back if V1 code is given. Thanks in advance.
Re: Remap Win key when it's pressed alone
Welcome to this AutoHotkey forum!
Possibly:
This may need adjustment for modifier combinations.
Possibly:
Code: Select all
#Requires AutoHotkey v2.0
ih := InputHook(), ih.KeyOpt('{All}', 'E')
LWin::ih.Start(), ih.Wait()
LWin Up::ih.Stop(), Send(ih.EndKey = '' ? '^{Home}' : '#{' ih.EndKey '}')
Re: Remap Win key when it's pressed alone
Wow, works like a magic! I learnd a lot from it. Thank you again!mikeyww wrote: ↑09 Aug 2023, 05:39Welcome to this AutoHotkey forum!
Possibly:
This may need adjustment for modifier combinations.Code: Select all
#Requires AutoHotkey v2.0 ih := InputHook(), ih.KeyOpt('{All}', 'E') LWin::ih.Start(), ih.Wait() LWin Up::ih.Stop(), Send(ih.EndKey = '' ? '^{Home}' : '#{' ih.EndKey '}')
Re: Remap Win key when it's pressed alone
Hmm, I actually find the behaviour is slightly different from expected. The input hook will end when Win is released so Win + Tab is not triggered instantly. And sending '#{' ih.EndKey '}' doesn't work when the end is a modifier, e.g. Win + Ctrl + → doesn't work (Ctrl + Win + → does though). I tried something like this but with no luck.mikeyww wrote: ↑09 Aug 2023, 05:39Welcome to this AutoHotkey forum!
Possibly:
This may need adjustment for modifier combinations.Code: Select all
#Requires AutoHotkey v2.0 ih := InputHook(), ih.KeyOpt('{All}', 'E') LWin::ih.Start(), ih.Wait() LWin Up::ih.Stop(), Send(ih.EndKey = '' ? '^{Home}' : '#{' ih.EndKey '}')
Code: Select all
#Requires AutoHotkey v2.0
ih := InputHook()
ih.KeyOpt('{All}', 'E')
ih.KeyOpt("{LCtrl}{RCtrl}{LAlt}{RAlt}{LShift}{RShift}", "-E")
LWin::ih.Start()
ih.Wait()
LWin Up::{
Send(ih.EndKey = '' ? '^{Home}' : '#' ih.EndMods '{' ih.EndKey '}')
}
Re: Remap Win key when it's pressed alone
Could try:
Test the script before you change it.
Code: Select all
#Requires AutoHotkey v2.0
ih := InputHook(), ih.KeyOpt('{All}', 'E')
LWin Up::ih.Stop(), Send(ih.EndKey = '' ? '^{Home}' : '{LWin up}')
LWin:: {
ih.Start(), ih.Wait()
If ih.EndKey != ''
Send '{LWin down}{' ih.EndKey ' down}'
}
Re: Remap Win key when it's pressed alone Topic is solved
Try this:
Code: Select all
#Requires Autohotkey v2.0
~LWin::Send "{Blind}{VKFF}"
~LWin up::{
if (A_PriorKey = "LWin")
Send "^{Home}"
}
Re: Remap Win key when it's pressed alone
Yeah, that makes more sense!
Re: Remap Win key when it's pressed alone
I tried the scripts proposed in this discussion and they work, but they interfere with the touchpad. I remapped the three-finger touch on my touchpad to ctrl + r, but when the script is running, other combinations are sent.
With:
#p is sent, after only 'r'.
With:
is sent #p and #<
With:
Code: Select all
ih := InputHook()
ih.KeyOpt('{All}', 'E')
ih.KeyOpt("{LCtrl}{RCtrl}{LAlt}{RAlt}{LShift}{RShift}", "-E")
LWin::ih.Start()
ih.Wait()
LWin Up::{
Send(ih.EndKey = '' ? '!{Space}' : '#' ih.EndMods '{' ih.EndKey '}')
}
With:
Code: Select all
ih := InputHook(), ih.KeyOpt('{All}', 'E')
LWin Up:: ih.Stop(), Send(ih.EndKey = '' ? '!{Space}' : '{LWin up}')
LWin:: {
ih.Start(), ih.Wait()
If ih.EndKey != ''
Send '{LWin down}{' ih.EndKey ' down}'
}