-
Notifications
You must be signed in to change notification settings - Fork 2
/
RDPKey.ahk
146 lines (130 loc) · 4.04 KB
/
RDPKey.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
; MIT License
; Copyright (c) 2016 Ken Wang
; Permission is hereby granted, free of charge, to any person obtaining a copy
; of this software and associated documentation files (the "Software"), to deal
; in the Software without restriction, including without limitation the rights
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
; copies of the Software, and to permit persons to whom the Software is
; furnished to do so, subject to the following conditions:
; The above copyright notice and this permission notice shall be included in all
; copies or substantial portions of the Software.
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
; SOFTWARE.
#SingleInstance force
#Include %A_ScriptDir%
#include common.ahk
If(!A_IsCompiled)
Menu, Tray, Icon, RDPKey16.ico
If(A_IsCompiled)
Menu, Tray, NoStandard
Menu, Tray, Add, &Help, ShowHelp
Menu, Tray, Default, &Help
Menu, Tray, Add, &About, ShowAbout
Menu, Tray, Add, E&xit, DoExit
Menu, Tray, Tip, RDP Key
return
ShowHelp:
MsgBox, , Hotkeys, Ctrl-Shift-CapsLock:`tMinimize/restore RDP window`nCtrl-CapsLock:`tRotate between RDP windows`nAlt-CapsLock:`tSwitch between 2 most recent RDP windows`nAlt-Shift-CapsLock:`tRestore fullscreen RDP into window mode
return
ShowAbout:
MsgBox, , RDP Key, Any question/feedback please contact Ken (https://github.com/gildorwang/RDP-Key)
return
DoExit:
ExitApp
return
#If !A_IsCompiled
; Reload AHK script
$!s::
SetTitleMatchMode, 2
Send, !s
IfWinActive, RDP.ahk
{
Info(A_ScriptName, "Reloaded")
Reload
}
return
#If
; [RDP] Minimize/restore RDP windows
^+CapsLock::
if(IsRDCMWinActive())
{
; Store the title of the topmost one
WinGetActiveTitle, RDCMWindowTitle
Loop
{
; Need a short sleep here for focus to restore properly.
Sleep 50
WinMinimize
GetCenterPos(centerX, centerY)
WinAtPos(centerX, centerY, title)
WinActivate % title
; Continue to minimize other RDP windows
} Until (!IsRDCMWinActive())
Info(RDCMWindowTitle, "Minimized")
}
else if (RDCMWindowTitle != "")
{
SetTitleMatchMode 3
WinActivate %RDCMWindowTitle%
Info(RDCMWindowTitle, "Restored")
}
return
; [RDP] Restore fullscreen remote desktop into a window
!+CapsLock::
if(IsRDCMWinActive())
{
Send ^!{CtrlBreak}
}
return
; [RDP] Rotate between RDP windows
^CapsLock::
if (OldTime = "") {
OldTime := A_TickCount
;next: whether the next window should be activated; otherwise the first one
next := false
}
else {
next := (A_TickCount - OldTime) < 800
OldTime := A_TickCount
}
if (next && OldIndex <> "") {
OldIndex := Mod(OldIndex, Wins) + 1
ahkId := Wins%OldIndex%
WinActivate ahk_id %ahkId%
WinGetTitle, winN_title, ahk_id %ahkId%
}
else{
; Go the normal way
OldIndex := SwitchRDCMWin()
}
return
; [RDP] Switch between the 2 most recent RDP windows
!CapsLock::
SwitchRDCMWin()
return
IsRDCMWinActive() {
return (WinActive("ahk_class TscShellContainerClass"))
}
SwitchRDCMWin() {
local wins2_title, wins1_title
WinGet, Wins, List, ahk_class TscShellContainerClass
if (Wins > 1) {
WinActivate ahk_id %Wins2%
WinGetTitle, wins2_title, ahk_id %Wins2%
return 2
}
else if (Wins = 1) {
WinActivate ahk_id %Wins1%
WinGetTitle, wins1_title, ahk_id %Wins1%
return 1
}
else {
Info("No more RDP windows", "RDP Key")
return 0
}
}