It seems that when RDP is in full-screen mode, AutoHotkey does not capture the WIN
+CTRL
+RIGHT
/LEFT
hotkeys, so any solution involving these hotkeys won't work.
I've searched for key combinations that RDP doesn't capture (and which are comfortable to use), so I've come up with ALT
+CapsLock
.
Then, I created a simple AutoHotkey script that capture ALT
+CapsLock
and uses this helper DLL to switch between desktops via API instead of sending hotkeys (I think it's more reliable).
https://github.com/Ciantic/VirtualDesktopAccessor
Basically, I copied some code from the project's V2 example and add the ALT
+CapsLock
handling.
This is my script:
; https://github.com/Ciantic/VirtualDesktopAccessor
SetWorkingDir(A_ScriptDir)
; Path to the DLL, relative to the script
VDA_PATH := A_ScriptDir . "\VirtualDesktopAccessor.dll"
hVirtualDesktopAccessor := DllCall("LoadLibrary", "Str", VDA_PATH, "Ptr")
GetDesktopCountProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "GetDesktopCount", "Ptr")
GoToDesktopNumberProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "GoToDesktopNumber", "Ptr")
GetCurrentDesktopNumberProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "GetCurrentDesktopNumber", "Ptr")
IsWindowOnCurrentVirtualDesktopProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "IsWindowOnCurrentVirtualDesktop", "Ptr")
IsWindowOnDesktopNumberProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "IsWindowOnDesktopNumber", "Ptr")
MoveWindowToDesktopNumberProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "MoveWindowToDesktopNumber", "Ptr")
IsPinnedWindowProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "IsPinnedWindow", "Ptr")
GetDesktopNameProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "GetDesktopName", "Ptr")
SetDesktopNameProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "SetDesktopName", "Ptr")
CreateDesktopProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "CreateDesktop", "Ptr")
RemoveDesktopProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "RemoveDesktop", "Ptr")
; On change listeners
RegisterPostMessageHookProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "RegisterPostMessageHook", "Ptr")
UnregisterPostMessageHookProc := DllCall("GetProcAddress", "Ptr", hVirtualDesktopAccessor, "AStr", "UnregisterPostMessageHook", "Ptr")
GetDesktopCount() {
global GetDesktopCountProc
count := DllCall(GetDesktopCountProc, "Int")
return count
}
MoveCurrentWindowToDesktop(number) {
global MoveWindowToDesktopNumberProc, GoToDesktopNumberProc
activeHwnd := WinGetID("A")
DllCall(MoveWindowToDesktopNumberProc, "Ptr", activeHwnd, "Int", number, "Int")
DllCall(GoToDesktopNumberProc, "Int", number, "Int")
}
GoToPrevDesktop() {
global GetCurrentDesktopNumberProc, GoToDesktopNumberProc
current := DllCall(GetCurrentDesktopNumberProc, "Int")
last_desktop := GetDesktopCount() - 1
; If current desktop is 0, go to last desktop
if (current = 0) {
MoveOrGotoDesktopNumber(last_desktop)
} else {
MoveOrGotoDesktopNumber(current - 1)
}
return
}
GoToNextDesktop() {
global GetCurrentDesktopNumberProc, GoToDesktopNumberProc
current := DllCall(GetCurrentDesktopNumberProc, "Int")
last_desktop := GetDesktopCount() - 1
; If current desktop is last, go to first desktop
if (current = last_desktop) {
MoveOrGotoDesktopNumber(0)
} else {
MoveOrGotoDesktopNumber(current + 1)
}
return
}
GoToDesktopNumber(num) {
global GoToDesktopNumberProc
DllCall(GoToDesktopNumberProc, "Int", num, "Int")
return
}
MoveOrGotoDesktopNumber(num) {
; If user is holding down Mouse left button, move the current window also
if (GetKeyState("LButton")) {
MoveCurrentWindowToDesktop(num)
} else {
GoToDesktopNumber(num)
}
return
}
;------------------VirtualDesktopAccessor------------------
!Capslock:: ;ALT+CapsLock
{
GoToNextDesktop()
}