I use Win-key combinations a lot (native ones and hotkeys), but my new keyboard doesn't have an RWin key. I also use the AppsKey and I figure it would be better to use it as a Win-key, but only when used in combination: if pressed on its own, AppsKey brings up the menu; if it's held and something else is pressed, it acts like the LWin key.
It was pretty complicated for me to figure out exactly the right lines to use to get the desired result, so I figure it could help someone else out. If there's an easier way, please let me know.
Code: Select all
*AppsKey::Send {Blind}{LWin Down} ; *Left Windows key in combination; AppsKey on its own
*AppsKey Up:: ; *LWin in combination; AppsKey on its own
If (A_PriorKey = "AppsKey") ; if no other button pressed (AppsKey just pressed and released)
Send {Ctrl Down}{LWin Up}{Ctrl Up}{AppsKey}
Else ; if any other button pressed (AppsKey used as Win in keycombo)
Send {Ctrl Down}{LWin Up}{Ctrl Up}
Return
AppsKey & l:: ; if AppsKey+L pressed (AppsKey remapping doesn't work for Win+L keycombo)
ActiveHwnd := WinExist("A") ; store active window
WinActivate ahk_class Shell_TrayWnd ; change active window to tray (so "L" and menu won't be sent to active window)
Send {Ctrl Down}{AppsKey Up}{Ctrl Up}
WinActivate ahk_id %ActiveHwnd%
DllCall("LockWorkStation")
Return
Edit: If anyone knows how to get it to function with modifiers in any order (e.g. Ctrl+AppsKey+someletter vs AppsKey+Ctrl+someletter) while keeping the AppsKey+L hotkey, please let me know.