-
Notifications
You must be signed in to change notification settings - Fork 2
/
#global_functions.ahk
171 lines (157 loc) · 4.65 KB
/
#global_functions.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
;#################################################################
;##### CfK -- core -- Global functions
;# = Super, ^ = Ctrl, ! = Alt, + = Shift, ^>! = AltGr
ShowToolTip(sText, iDuration)
{
ToolTip, %sText%
SetTimer, RemoveToolTip, %iDuration%
}
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return
BringToFront(process_id)
{
; ; Process, wait, %process_id%, 4
; ; WinActivate, ahk_pid %process_id%
; ; WinRestore, ahk_pid %process_id%
; ; WinSet, Top,, ahk_pid %process_id%
; WinWait, ahk_pid %process_id%, , 10
; WinActivate, ahk_pid %process_id%
; WinSet, Top, , ahk_pid %process_id%
; Loop, 12
; {
; if WinExist("ahk_pid " . process_id)
; {
; WinActivate, ahk_pid %process_id%
; WinSet, Top, , ahk_pid %process_id%
; ; ShowToolTip("Brought to Front", 2000)
; Break
; }
; ; ShowToolTip("failed", 100)
; Sleep, 250
; }
return
}
hasValue(haystack, needle) {
if (!isObject(haystack))
return false
if (haystack.Length()==0)
return false
for k, v in haystack
if (v == needle)
return true
return false
}
RunGetOutput(cmd) {
shell := ComObjCreate("WScript.Shell")
exec := shell.Exec("cmd.exe /q /c " cmd)
if (A_LastError)
return 0
return exec.StdOut.ReadAll()
}
inRDP() {
RegRead, CN, HKCU, Volatile Environment, CLIENTNAME
RegRead, SN, HKCU, Volatile Environment, SESSIONNAME
If (SN == "")
{
Loop, Reg, HKEY_CURRENT_USER\Volatile Environment, K
{
RegRead, CN, HKCU, Volatile Environment\%a_LoopRegName%, CLIENTNAME
RegRead, SN, HKCU, Volatile Environment\%a_LoopRegName%, SESSIONNAME
If (SN <> "")
break
}
}
If (SN == "")
return ""
Else
return CN
}
updateTrayIcon() {
If A_ISSUSPENDED = 1
Menu, Tray, Icon, .\#ico\CfKs.ico, 1, 1
Else If A_ISSUSPAUSED = 1
Menu, Tray, Icon, .\#ico\CfKp.ico, 1, 1
Else
Menu, Tray, Icon, .\#ico\CfK.ico, 1, 1
}
; isWinVisible(WinTitle)
; {
; WinGet, Style, Style, %WinTitle%
; Transform, Result, BitAnd, %Style%, 0x10000000 ; 0x10000000 is WS_VISIBLE.
; if (Result <> 0) ;Window is Visible
; {
; Return 1
; }
; Else ;Window is Hidden
; {
; Return 0
; }
; }
; Retrieves the size of the monitor, the mouse is present
activeMonitorInfo(ByRef monitor_left, ByRef monitor_top, ByRef monitor_width, ByRef monitor_height) {
CoordMode, Mouse, Screen
MouseGetPos, mouse_x , mouse_y
SysGet, monitor_count, MonitorCount
Loop %monitor_count%
{
SysGet, curMon, Monitor, %a_index%
if (mouse_x >= curMonLeft and mouse_x <= curMonRight and mouse_y >= curMonTop and mouse_y <= curMonBottom)
{
monitor_left := curMonLeft
monitor_top := curMonTop
monitor_height := curMonBottom - curMonTop
monitor_width := curMonRight - curMonLeft
return
}
}
}
; Retrieves the workarea on monitor, the mouse is present
activeMonitorWorkArea(ByRef workarea_left, ByRef workarea_top, ByRef workarea_width, ByRef workarea_height) {
CoordMode, Mouse, Screen
MouseGetPos, mouse_x , mouse_y
SysGet, monitor_count, MonitorCount
Loop %monitor_count%
{
SysGet, curMon, Monitor, %a_index%
if (mouse_x >= curMonLeft and mouse_x <= curMonRight and mouse_y >= curMonTop and mouse_y <= curMonBottom)
{
SysGet, workArea, MonitorWorkArea, %a_index%
workarea_left := workAreaLeft
workarea_top := workAreaTop
workarea_height := workAreaBottom - workAreaTop
workarea_width := workAreaRight - workAreaLeft
return
}
}
}
; Retrives the size and position of windows taskbar
taskbarInfo(ByRef taskbar_left, ByRef taskbar_top, ByRef taskbar_width, ByRef taskbar_height) {
WinGetPos, taskbar_left, taskbar_top, taskbar_width, taskbar_height, ahk_class Shell_TrayWnd
}
RunWithProxy(ByRef target) {
; cmd /V /C "set http_proxy=http://sfl-hza-prx-02.schaeffler.com:8080&&C:\CfK\Clementine\clementine.exe"
target_call := "SET http_proxy=http://sfl-hza-prx-02.schaeffler.com:8080"
target_call := target_call . " && SET http_proxys=http://sfl-hza-prx-02.schaeffler.com:8080"
target_call := target_call . " && SET ftp_proxy=http://sfl-hza-prx-02.schaeffler.com:8080"
target_call := target_call . " && START " . target
Run, cmd.exe /c %target_call%, , , NewPID
BringToFront(NewPID)
}
TriggerWebProxyAuthentication() {
; US public broadcasting GDPR-compliant site, very small
URL := "https://text.npr.org/robots.txt"
try {
ie := ComObjCreate("InternetExplorer.Application")
ie.Visible := false ; hide IE
ie.Navigate(URL)
; give the browser some time to load the url
sleep 5000
; quit the instance of the IE
ie.quit()
return 1
} catch {
return 0
}
}