Skip to content

Commit c60f55b

Browse files
authored
Enhance compatibility #7 + migrate to AHK v2.0
Added support for Hyper-V Virtual Machine Connection (#7). The new WinWaitActive name pattern is checked against the process name instead of the window name, so it should now work with any system language.
1 parent fc9fc0f commit c60f55b

File tree

2 files changed

+33
-43
lines changed

2 files changed

+33
-43
lines changed

RDPHotkeyHelper.ahk

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
;@Ahk2Exe-SetMainIcon rhh.ico
2-
;@Ahk2Exe-Set FileVersion, 1.1.1.0
3-
;@Ahk2Exe-Set ProductVersion, 1.1.1.0
2+
;@Ahk2Exe-Set FileVersion, 1.2.0.0
3+
;@Ahk2Exe-Set ProductVersion, 1.2.0.0
4+
;@Ahk2Exe-PostExec "MPRESS.exe" "%A_WorkFileName%" -q -x, 0,, 1, 1
45

56
#SingleInstance Force
6-
#NoEnv
7-
#KeyHistory 0
8-
UpdateTrayIcon()
9-
Menu, Tray, Tip, RDP Hotkey Helper
10-
Menu, Tray, NoStandard
11-
Menu, Tray, Add, Exit
12-
13-
global RdpWindowTitle := % (SubStr(A_Language, -1) = "07" ? " - Remotedesktop" : " - Remote Desktop") ; matches both classic RDP client and the app from the Microsoft store
14-
SetTitleMatchMode, 2
15-
DetectHiddenWindows, On
7+
KeyHistory(0)
8+
If (!A_IsCompiled && FileExist("rhh.ico")) {
9+
TraySetIcon("rhh.ico")
10+
}
11+
A_IconTip := "RDP Hotkey Helper"
12+
Tray:= A_TrayMenu
13+
Tray.Delete()
14+
Tray.Add("Exit", Exit)
15+
ExeNamesPattern := "i)\\(mstsc|ApplicationFrameHost|VMConnect)\.exe$"
16+
SetTitleMatchMode("RegEx")
1617
While true {
17-
WinWaitActive, %RdpWindowTitle%
18-
Suspend, On ; rebind all hotkeys, otherwise they won't work in RDP fullscreen mode
19-
Suspend, Off
20-
Sleep, 250
21-
WinWaitNotActive, %RdpWindowTitle%
18+
global RdpHwnd := 0
19+
WinWaitActive("ahk_exe " ExeNamesPattern)
20+
RdpHwnd := WinExist("A")
21+
Suspend(true) ; rebind all hotkeys, otherwise they won't work in RDP fullscreen mode
22+
Suspend(false)
23+
Sleep(250)
24+
WinWaitNotActive("ahk_id " RdpHwnd)
2225
}
2326

2427
#UseHook
@@ -31,37 +34,27 @@ Media_Stop::PassToLocalMachine()
3134
Media_Play_Pause::PassToLocalMachine()
3235

3336
PassToLocalMachine() {
34-
WinGetText, ActiveWindowTitle, A
35-
If Not InStr(ActiveWindowTitle, RdpWindowTitle) {
36-
Send {%A_ThisHotKey%}
37+
If (RdpHwnd == 0 || WinExist("A") != RdpHwnd) {
38+
Send("{" A_ThisHotKey "}")
3739
Return
3840
}
3941
WM_APPCOMMAND := 0x0319
4042
If (A_ThisHotKey = "Volume_Mute")
41-
PostMessage, WM_APPCOMMAND, 0, 8<<16,, ahk_class Shell_TrayWnd ; APPCOMMAND_VOLUME_MUTE
43+
PostMessage(WM_APPCOMMAND, 0, 8<<16, , "ahk_class Shell_TrayWnd") ; APPCOMMAND_VOLUME_MUTE
4244
Else If (A_ThisHotKey = "Volume_Down")
43-
PostMessage, WM_APPCOMMAND, 0, 9<<16,, ahk_class Shell_TrayWnd ; APPCOMMAND_VOLUME_DOWN
45+
PostMessage(WM_APPCOMMAND, 0, 9<<16, , "ahk_class Shell_TrayWnd") ; APPCOMMAND_VOLUME_DOWN
4446
Else If (A_ThisHotKey = "Volume_Up")
45-
PostMessage, WM_APPCOMMAND, 0, 10<<16,, ahk_class Shell_TrayWnd ; APPCOMMAND_VOLUME_UP
47+
PostMessage(WM_APPCOMMAND, 0, 10<<16, , "ahk_class Shell_TrayWnd") ; APPCOMMAND_VOLUME_UP
4648
Else If (A_ThisHotKey = "Media_Next")
47-
PostMessage, WM_APPCOMMAND, 0, 11<<16,, ahk_class Shell_TrayWnd ; APPCOMMAND_MEDIA_NEXTTRACK
49+
PostMessage(WM_APPCOMMAND, 0, 11<<16, , "ahk_class Shell_TrayWnd") ; APPCOMMAND_MEDIA_NEXTTRACK
4850
Else If (A_ThisHotKey = "Media_Prev")
49-
PostMessage, WM_APPCOMMAND, 0, 12<<16,, ahk_class Shell_TrayWnd ; APPCOMMAND_MEDIA_PREVIOUSTRACK
51+
PostMessage(WM_APPCOMMAND, 0, 12<<16, , "ahk_class Shell_TrayWnd") ; APPCOMMAND_MEDIA_PREVIOUSTRACK
5052
Else If (A_ThisHotKey = "Media_Stop")
51-
PostMessage, WM_APPCOMMAND, 0, 13<<16,, ahk_class Shell_TrayWnd ; APPCOMMAND_MEDIA_STOP
53+
PostMessage(WM_APPCOMMAND, 0, 13<<16, , "ahk_class Shell_TrayWnd") ; APPCOMMAND_MEDIA_STOP
5254
Else If (A_ThisHotKey = "Media_Play_Pause")
53-
PostMessage, WM_APPCOMMAND, 0, 14<<16,, ahk_class Shell_TrayWnd ; APPCOMMAND_MEDIA_PLAY_PAUSE
55+
PostMessage(WM_APPCOMMAND, 0, 14<<16, , "ahk_class Shell_TrayWnd") ; APPCOMMAND_MEDIA_PLAY_PAUSE
5456
}
5557

56-
UpdateTrayIcon() {
57-
If Not (A_IsCompiled) {
58-
try {
59-
Menu, Tray, Icon, rhh.ico
60-
}
61-
} Else {
62-
Menu, Tray, Icon, *
63-
}
58+
Exit(*) {
59+
ExitApp()
6460
}
65-
66-
Exit:
67-
ExitApp

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
# RDPHotkeyHelper
2-
RDPHotkeyHelper is an AutoHotkey script which redirects media keys to the local machine while working within a remote desktop session. It works with Microsoft's standard remote desktop connection and the Microsoft store app.
3-
Using media keys on the remote host is still possible by simply holding down ctrl or alt when pressing the media key.
4-
5-
### Note
6-
Window detection is language dependent in order to also support the store app. If your client is not detected, replace [` - Remote Desktop`](https://github.com/neon-dev/RDPHotkeyHelper/blob/main/RDPHotkeyHelper.ahk#L13) with your localized window title suffix.
2+
RDPHotkeyHelper is an AutoHotkey v2 script which redirects media keys to the local machine while working within a remote desktop session. It works with Microsoft's standard remote desktop connection, the Microsoft store app, as well as the Hyper-V Virtual Machine Connection.
3+
Using media keys on the remote host is still possible by holding down `Ctrl` or `Alt` when pressing the media key.

0 commit comments

Comments
 (0)