-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappSend.ahk
More file actions
87 lines (76 loc) · 2.4 KB
/
appSend.ahk
File metadata and controls
87 lines (76 loc) · 2.4 KB
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
;------------------------------------
; AUTOHOTKEY'S HOTKEYS :
;------------------------------------
; # = Windows Key
; ! = ALT
;------------------------------------
;------------------------------------
; COMMANDS SENT {} :
;------------------------------------
; ^ = CTRL
;------------------------------------
; Get the HWND of the software's main window.
getSoftwareHwnd(processExe) {
WinGet, softwareHwnd, ID, ahk_exe %processExe%
; We need the app's third top level window, so get next twice.
; softwareHwnd := DllCall("GetWindow", "uint", softwareHwnd, "uint", 2)
; softwareHwnd := DllCall("GetWindow", "uint", softwareHwnd, "uint", 2)
Return softwareHwnd
}
getSoftwareHwndAtCord(x, y) {
hWnd := DllCall("WindowFromPoint", "UInt64", x|(y << 32), "Ptr")
Return hWnd
}
; Send a key to a software.
sendKeyToSoftware(softwareHwnd, key, method) {
if (method == "PostMessage" ) {
PostMessage, 0x319,, 0xE0000,, ahk_id %softwareHwnd%
}
if (method == "ControlSend" ) {
; Chromium ignores keys when it isn't focused.
; Focus the document window without bringing the app to the foreground.
ControlFocus, Chrome_RenderWidgetHostHWND1, ahk_id %softwareHwnd%
ControlSend, , %key%, ahk_id %softwareHwnd%
}
Return
}
volume(type) {
processName := "spotify.exe"
WinGetTitle, winname, ahk_exe %processName%
if (type == "up"){
if (winname == "Spotify Premium" ) {
softwareHwnd := getSoftwareHwndAtCord(1766, -1055)
sendKeyToSoftware(softwareHwnd, "{Up}", "ControlSend")
} else {
softwareHwnd := getsoftwareHwnd("spotify.exe")
sendKeyToSoftware(softwareHwnd, "^{Up}", "ControlSend")
}
}
if (type == "down"){
if (winname == "Spotify Premium" ) {
softwareHwnd := getSoftwareHwndAtCord(1766, -1055)
sendKeyToSoftware(softwareHwnd, "{Down}", "ControlSend")
} else {
softwareHwnd := getsoftwareHwnd("spotify.exe")
sendKeyToSoftware(softwareHwnd, "^{Down}", "ControlSend")
}
}
Return
}
; F14:: sendKeyToSoftware("spotify.exe", "^{Up}", "ControlSend") ; Spotify: Volume up
; F15:: sendKeyToSoftware("spotify.exe", "^{Down}", "ControlSend") ; Spotify: Volume down
F14:: volume("up")
F15:: volume("down")
; Win+alt+o: Show Spotify
#!o::
{
softwareHwnd := getsoftwareHwnd("spotify.exe")
WinGet, style, Style, ahk_id %softwareHwnd%
if (style & 0x10000000) { ; WS_VISIBLE
WinHide, ahk_id %softwareHwnd%
} Else {
WinShow, ahk_id %softwareHwnd%
WinActivate, ahk_id %softwareHwnd%
}
Return
}