Remap AppsKey to Windows key keeping AppsKey functionality

Post your working scripts, libraries and tools for AHK v1.1 and older
itssamy
Posts: 2
Joined: 13 Feb 2017, 10:53

Remap AppsKey to Windows key keeping AppsKey functionality

13 Feb 2017, 11:32

Hey all,

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
Note: the remap works perfectly excluding default windows keycombos (e.g. Win+L to lock) if you remove the "AppsKey & l" section.

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.
User avatar
rommmcek
Posts: 1476
Joined: 15 Aug 2014, 15:18

Re: Remap AppsKey to Windows key keeping AppsKey functionality

05 Mar 2017, 05:25

Try this one:

Code: Select all

AppsKey::
Send, {RWin Down}
KeyWait, AppsKey
if (A_TimeSincePriorHotkey < 400)&&(A_ThisHotkey = A_PriorHotkey)
    Send, {Rwin Up}  ; double press triggers pure RWin
else if (A_ThisHotkey = "AppsKey")
    Send, {Ctrl Down}{RWin Up}{Ctrl Up}{AppsKey}
return
AppsKey & l::DllCall("LockWorkStation")
AppsKey & -::Send, #{-}
AppsKey & +::Send, #{+}
AppsKey & i::Send, #{i}
; ... etc. for every combination
This one I tested!
itssamy
Posts: 2
Joined: 13 Feb 2017, 10:53

Re: Remap AppsKey to Windows key keeping AppsKey functionality

08 Mar 2017, 11:17

Ah, I was trying to avoid mapping individual hotkeys.

Example: I have a script that changes window size when I press Win+Up, one that pauses music on Win+Space, and another that skips current song on Ctrl+Win+Right, and I wanted not to have to map AppsKey+Up, AppsKey+Space and Ctrl+AppsKey+Right. Basically trying to avoid double-remaps.

I appreciate the effort though and if you figure anything else out (especially how to make AppsKey a modifier without losing AppsKey+L = lock), please let me know!
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Remap AppsKey to Windows key keeping AppsKey functionality

08 Mar 2017, 11:34

itssamy wrote: I appreciate the effort though and if you figure anything else out (especially how to make AppsKey a modifier without losing AppsKey+L = lock), please let me know!
try this:
https://github.com/lydell/dual

maybe that helps

User avatar
rommmcek
Posts: 1476
Joined: 15 Aug 2014, 15:18

Re: Remap AppsKey to Windows key keeping AppsKey functionality

19 Mar 2017, 09:52

If you don't like remapping, you have to accept time leg, I guess!

Code: Select all

AppsKey::
    ToolTip % " ", 5000, 3000
    WinActivate, ahk_class tooltips_class32
    if (AppKeys > 0) {
        AppKeys++
        return
        }
    AppKeys := 1
    SetTimer, AppKey, 350
return

AppKey:
    if (AppKeys = 1) {
        Send, {RWin down}
        KeyWait, AppsKey, U
        Send, !{RWin Up}
        ToolTip
        if (A_PriorKey = "AppsKey")
            Send, {AppsKey}
        else if (A_PriorKey = "l")
            DllCall("LockWorkStation")
        }
    else if (AppKeys = 2) {
        Send, !{RWin Up}{RWin}
        ToolTip
        }
    AppKeys := 0
return
zhotkey

Re: Remap AppsKey to Windows key keeping AppsKey functionality

25 Mar 2017, 15:19

I was only able to get rommmcek code working, but it doesn't seem to work with multiple hotkeys, I tried:
AppsKey & !k::Send, #{!k}
AppsKey & ! & k::Send, #{!k}
AppsKey & {! & k}::Send, #{!k}
AppsKey & {! & k}::Send, #{! & k}

with no success (Invalid hotkey). Any ideas?
User avatar
rommmcek
Posts: 1476
Joined: 15 Aug 2014, 15:18

Re: Remap AppsKey to Windows key keeping AppsKey functionality

29 Mar 2017, 11:44

It seems, you have syntactical problems. Try this:

Code: Select all

AppsKey & k::
if GetKeyState( "Alt", "P")
	Send, #!{k}
else
	Send, #{k}
return
Note: didn't test it extensively, so you may need to modify it!
zhotkey

Re: Remap AppsKey to Windows key keeping AppsKey functionality

31 Mar 2017, 08:55

Thanks rommcek, your solution works for just about all key combinations. However, it doesn't work for Appskey & Ctrl & p, it gets to the proper loop with my display message, but it brings up the default Windows projector mode like just pressing Appskey & p or #p instead of my redefined #^p It does work properly for Appskey & Alt & p

AppsKey & p::
If GetKeyState("Ctrl","P")
{
MsgBox You pressed AppsKey & e while holding Ctrl
Send, #^{p}
}
Else If GetKeyState("Alt","P")
{
MsgBox You pressed AppsKey & e while holding Alt
Send, #!{p}
}
Else
{
MsgBox You pressed AppsKey & p
Send, #{p}
}
Return
User avatar
rommmcek
Posts: 1476
Joined: 15 Aug 2014, 15:18

Re: Remap AppsKey to Windows key keeping AppsKey functionality

01 Apr 2017, 08:31

You're almost there! Try:

Code: Select all

AppsKey & p::
if GetKeyState( "Alt", "P") && GetKeyState( "Ctrl", "P") 
	Send, #!^{p}
else if GetKeyState( "Alt", "P") && !GetKeyState( "Ctrl", "P")
	Send, #!{p}
else if !GetKeyState( "Alt", "P") && GetKeyState( "Ctrl", "P")
	Send, #^{p}
else
	Send, #{p}
return
Again: This is pseudo code, I never ran it, so wish you best luck!
zhotkey

Re: Remap AppsKey to Windows key keeping AppsKey functionality

02 Apr 2017, 12:39

rommmcek, your logic works and so does my previous post if I run the actual key mapped command instead of just sending key assignments for the "p" key, other letters work without resorting to running the actual key mapped command. Thanks for the additional logic of also using Appskey & Ctrl & Alt.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: hiahkforum and 227 guests