Building off electrotype's answer I have an AHK script that will enable Ctrl+Win+Left and Ctrl+Win+Right hotkeys to switch desktops on the local computer, from within a full screen RDP session, without sacrificing any other keys within the RDP session - i.e. Alt+Tab and similar all still work as normal within the RDP session.
As we want the regular shortcut key to work on the remote computer, you must have "Only when using the full screen" for the "Apply Windows key combinaitons" setting when starting the RDP session.
I actually based my script off another script I found on the AHK forums.
What it does:
- Run the script on your local machine (not on the remote desktop). I pasted mine into
C:\users\<user>\documents\AutoHotkey.ahk
so it runs when i start ahk with no arguments.
- If you are inside an RDP session and press Ctrl+Win+(Left or right) the script first sends Ctrl+Alt+Home to focus the RDP title bar then sends the switch desktop key combo to actually switch the desktop.
Note: it gets a little buggy when using two or more virtual-remote desktops (eg. one local virtual desktop, two virtual desktops with a fullscreen RDP window on each) but I don't have time to work on it any more right now. The issue is when you switch from one virtual-remote desktop to another, you have to unbind and rebind the hot key and it's having trouble detecting this (though it shouldn't - the RDP title bar has a different window class but it doesn't always pick this up).
Ahk script:
;setTimer, windowwatch, 500
#persistent
#usehook
SLEEP_VAL := 500
DEBUG := false
keys_bound := false
while true {
;Debug("Waiting")
sleep, SLEEP_VAL
keys_bound := WaitBind()
}
WaitBind() {
WinWaitActive, ahk_class TscShellContainerClass
Debug("bind")
hotkey LWin & Left, ctrl_win_left_key, on
hotkey LWin & Right, ctrl_win_right_key, on
return true
}
WaitUnbind() {
WinWaitNotActive, ahk_class TscShellContainerClass
Debug("unbind")
hotkey LWin & Left, ctrl_win_left_key, off
hotkey LWin & Right, ctrl_win_right_key, off
return false
}
Debug(msg) {
global DEBUG
if (DEBUG) {
tooltip %msg%
settimer, TooltipClear, 2000
}
}
return
z_key:
; simple script for testing - change the z to 'he'
send, he
Debug("done z")
return
j_key:
; testing if we can activate the RDP title bar
send {Ctrl down}{Alt down}{Home}{Alt up}{Ctrl up}
Debug("done j")
Return
ctrl_win_left_key:
; we are intercepting all Win+Left combinations so we have to do Win+Shift+Left and Win+Left manually to preserve them inside the RDP
GetKeyState, shiftState, Shift
GetKeyState, ctrlState, Ctrl
if (shiftState = "D") {
; by default in windows Ctrl+Shift+Win+Left will act like Shift+Win+Left - shift takes precedence
Debug("done shift win left")
send {Shift down}{LWin down}{Left}{LWin up}{Shift up}
} else if (ctrlState = "D") {
Debug("done ctrl win left")
; the magic happens here
send {Ctrl down}{Alt down}{Home}{Alt up}{Ctrl up}
keys_bound := WaitUnbind()
;Sleep, SLEEP_VAL ;give the OS time to focus on the title bar
send {Ctrl down}{LWin down}{Left}{LWin up}{Ctrl up}
} else {
Debug("done win left")
send {LWin down}{Left}{LWin up}
}
Return
ctrl_win_right_key:
; we are intercepting all Win+Right combinations so we have to do Win+Shift+Right and Win+Right manually to preserve them inside the RDP
GetKeyState, shiftState, Shift
GetKeyState, ctrlState, Ctrl
if (shiftState = "D") {
; by default in windows Ctrl+Shift+Win+Left will act like Shift+Win+Left - shift takes precedence
Debug("done shift win right")
send {Shift down}{LWin down}{Right}{LWin up}{Shift up}
} else if (ctrlState = "D") {
Debug("done ctrl win right")
; the magic happens here
send {Ctrl down}{Alt down}{Home}{Alt up}{Ctrl up}
keys_bound := WaitUnbind()
;Sleep, SLEEP_VAL ;give the OS time to focus on the title bar
send {Ctrl down}{LWin down}{Right}{LWin up}{Ctrl up}
} else {
Debug("done win right")
send {LWin down}{Right}{LWin up}
}
Return
TooltipClear:
; just a routine to turn off tooltip after x milliseconds
tooltip
settimer, TooltipClear, off
Return
windowwatch:
ifwinactive ahk_class TscShellContainerClass
{
Debug("bind")
hotkey LWin & Left, ctrl_win_left_key, on
hotkey LWin & Right, ctrl_win_right_key, on
}
else
{
Debug("unbind")
hotkey LWin & Left, ctrl_win_left_key, off
hotkey LWin & Right, ctrl_win_right_key, off
}
Return
I need an answer on this too! – Antony – 2016-03-09T16:10:24.687
1Upvoting, because this would be great. It would be nice to choose which Windows key combinations apply to RDP or computer – MikeMurko – 2016-08-29T17:50:27.527