Reputation: 1814
I wish to remap only Left Windows key when pressed alone and keep every Left Windows key combination such as LWin+Left/Right etc
So far no solution I've tried worked very good: Sometimes the script does not intercept windows key and mostly doing something in between the default windows behavior and the autohotkey script behavior.
This is the script with the best results so far:
$LWin::
KeyWait, LWin, T0.3
If !ErrorLevel {
Send, +!{space}
}
Else {
Send, {LWin Down}
}
KeyWait, LWin
Send, {LWin Up}
Return
Things I've tried:
Upvotes: 8
Views: 1246
Reputation: 12204
Run the AHK elevated.
You say
Sometimes the script does not intercept windows key and mostly doing something in between the default windows behavior and the autohotkey script behavior.
If you encounter non-deterministic behavior of AutoHotKey, run it elevated, i.e. As Administrator.
I faced this problem often in my scripts until I have found that AHK does not reliably catch system-related shortcuts or keys (they sometimes work and sometimes don't) unless it is launched as administrator. The last system where this was not required was Windows XP. Troubles started with Windows 7.
Tip: If you want the AHK to be run elevated on every login of your user, run it using scheduled task (created via Task Scheduler) and give the task administrator privileges.
Upvotes: 2
Reputation: 10636
Try this:
LWin up::
If (A_PriorKey = "LWin") ; LWin was pressed alone
Send, +!{space}
return
; In this case its necessary to define a custom combination by using "&" or "<#"
; to avoid that LWin loses its original function as a modifier key:
<#d:: Send #d ; <# means LWin
Upvotes: 8