-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWinKeybinds.ahk
262 lines (219 loc) · 9.99 KB
/
WinKeybinds.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
;=====================================[ Welcome to My Windows 11 Keybindings ]====================================
;
; Welcome to my custom Windows 11 keybindings script, made with AutoHotkey!
; This script lets you use hotkeys for common actions to make your system easier to control.
; It includes features such as:
; - [Audio Management] : Volume Control + Audio and Microphone muting
; - [System Control] : Quick access to system shutdown, restart, lock, and sleep
; - [Shortcuts] : Launch File Explorer, Powershell and more with custom hotkeys
;
; Enjoy :)
;
;=====================================[ Let's Get Started :P ]====================================
currentActiveMenu := ""
;---------------------------------[ VARIABLES / MAIN CONFIGURATION ]---------------------------------
fileExplorerKey := "!e # Alt + E"
powershellKey := "!t # Alt + T"
toggleTaskbarKey := "!g # Alt + G"
openBrowserKey := "!f # Alt + F"
desktopShortcuts := "!s # Alt + S"
muteAudioKey := "Pause # Pause/Break"
muteMicKey := "Insert # Insert"
increaseVolumeKey := "!+Up # Alt + Shift + Up"
decreaseVolumeKey := "!+Down # Alt + Shift + Down"
systemControlKey := "!Backspace # Alt + Backspace"
reloadScriptKey := "^!r # Ctrl + Alt + R"
;---------------------------------[ HOTKEYS / MAIN CONFIGURATION ]---------------------------------
Hotkey, % GetHotkey(fileExplorerKey), OpenFileExplorer
Hotkey, % GetHotkey(powershellKey), OpenPowerShell
Hotkey, % GetHotkey(toggleTaskbarKey), ToggleTaskbarVisibility
Hotkey, % GetHotkey(openBrowserKey), OpenDefaultBrowser
Hotkey, % GetHotkey(desktopShortcuts), DesktopShortcuts
Hotkey, % GetHotkey(muteAudioKey), MuteUnmuteAudio
Hotkey, % GetHotkey(muteMicKey), MuteUnmuteMic
Hotkey, % GetHotkey(increaseVolumeKey), IncreaseVolume
Hotkey, % GetHotkey(decreaseVolumeKey), DecreaseVolume
Hotkey, % GetHotkey(systemControlKey), ShowPowerOptions
Hotkey, % GetHotkey(reloadScriptKey), ReloadScript
;---------------------------------[ HELP GUI ]---------------------------------
!?::
; Check if a menu is already open
if (currentActiveMenu != "") {
ToolTip, Please close the "%currentActiveMenu%" menu before opening something else.
SetTimer, RemoveToolTip, 1000
return
}
currentActiveMenu := "Keybinds Help"
Gui, Destroy
Gui, +Resize +MinSize +MaxSize ; Allow resizing but enforce a minimum size
; Add text and groups for keybinds help
Gui, Add, Text, x20 y10 w350 h20, --- Here are your keybinds for quick and easy system control! ---
Gui, Add, Text, x20 y35 w350 h30, -- To customize or change keybinds, edit the configuration in the script. --
Gui, Add, GroupBox, x20 y60 w340 h50, % Chr(0x1F527) " System Control"
Gui, Add, Text, x40 y80 w300 h20, % GetHotkeyDisplay(systemControlKey) ": Open Power Options"
Gui, Add, GroupBox, x20 y120 w340 h150, % Chr(0x2328) " Shortcuts"
Gui, Add, Text, x40 y140 w300 h20, % GetHotkeyDisplay(fileExplorerKey) ": Open File Explorer"
Gui, Add, Text, x40 y160 w300 h20, % GetHotkeyDisplay(openBrowserKey) ": Open Browser"
Gui, Add, Text, x40 y180 w300 h20, % GetHotkeyDisplay(powershellKey) ": Open Powershell"
Gui, Add, Text, x40 y200 w300 h20, % GetHotkeyDisplay(desktopShortcuts) ": Hide/Show Desktop Icons"
Gui, Add, Text, x40 y220 w300 h20, % GetHotkeyDisplay(toggleTaskbarKey) ": Toggle Taskbar Visibility"
Gui, Add, Text, x40 y240 w300 h20, % GetHotkeyDisplay(reloadScriptKey) ": Reload Script"
Gui, Add, GroupBox, x20 y280 w340 h110, % Chr(0x1F50A) " Audio Manager"
Gui, Add, Text, x40 y300 w300 h20, % GetHotkeyDisplay(muteAudioKey) ": Mute/Unmute Audio"
Gui, Add, Text, x40 y320 w300 h20, % GetHotkeyDisplay(muteMicKey) ": Mute/Unmute Mic"
Gui, Add, Text, x40 y340 w300 h20, % GetHotkeyDisplay(increaseVolumeKey) ": Increase Volume"
Gui, Add, Text, x40 y360 w300 h20, % GetHotkeyDisplay(decreaseVolumeKey) ": Decrease Volume"
Gui, Show, w380 h420, Keybinds Help
return
;---------------------------------[ AUDIO MANAGEMENT ]---------------------------------
MuteUnmuteAudio:
; Toggle audio mute state
if (audioMuted := !audioMuted) {
SoundSet, +1, MASTER, mute, 2 ; Replace 2 with your audio device ID <--- IMPORTANT
tooltipText := "Audio Off"
} else {
SoundSet, -1, MASTER, mute, 2 ; Replace 2 with your audio device ID <--- IMPORTANT
tooltipText := "Audio On"
}
ToolTip, %tooltipText%
SetTimer, RemoveToolTip, 1000
return
MuteUnmuteMic:
; Toggle mic mute state
if (micMuted := !micMuted) {
SoundSet, +1, MASTER, mute, 3 ; Replace 3 with your audio device ID <--- IMPORTANT
tooltipText := "Mic Off"
} else {
SoundSet, -1, MASTER, mute, 3 ; Replace 3 with your audio device ID <--- IMPORTANT
tooltipText := "Mic On"
}
ToolTip, %tooltipText%
SetTimer, RemoveToolTip, 1000
return
IncreaseVolume:
Send, {Volume_Up}
return
DecreaseVolume:
Send, {Volume_Down}
return
;---------------------------------[ SHORTCUTS ]---------------------------------
OpenFileExplorer:
Run, explorer.exe
return
OpenPowerShell:
Run, powershell.exe -NoExit -Command "cd $env:USERPROFILE\Downloads"
return
DesktopShortcuts:
DesktopIcons( Show:=-1 )
return
ToggleTaskbarVisibility:
HideShowTaskbar(hide := !hide)
return
OpenDefaultBrowser:
Run, % DefaultBrowser()
return
;---------------------------------[ SYSTEM CONTROL ]---------------------------------
ShowPowerOptions:
; If another menu is open, show a tooltip and exit
if (currentActiveMenu != "") {
ToolTip, Please close the "%currentActiveMenu%" menu before opening something else.
SetTimer, RemoveToolTip, 1000
return
}
currentActiveMenu := "Power Options"
; Destroy any existing GUI if it exists
Gui, Destroy
Gui Font, q5 s10, Arial Unicode MS
Gui, Add, Text, x20 y20 w220 h30, Choose an action:
Gui, Add, ListBox, vActionListBox w200 h120, Restart|Shutdown|Sleep|Logoff
Gui, Add, Button, gSelectAction w200 h30, Select
Gui, Show, , Power Options
return
~Enter::
; Handle Enter key press in Power Options menu
if !WinActive("Power Options")
return
Gui, Submit, NoHide
GoSub, SelectAction
return
SelectAction:
Gui, Submit
selectedAction := ActionListBox
Gui, Destroy
; Perform the selected action
if (selectedAction = "Restart")
Shutdown, 2
else if (selectedAction = "Shutdown")
Shutdown, 1
else if (selectedAction = "Sleep")
DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
else if (selectedAction = "Logoff")
Shutdown, 0
return
;---------------------------------[ MISC FUNCTIONS ]---------------------------------
;─────────────────────────────────────────[Function to hide or show the taskbar with auto-hide]─────────────────────────────────────────
; Script rewritten with improvements. Original inspiration from:
; https://www.autohotkey.com/boards/viewtopic.php?t=113777
; Thanks :)
HideShowTaskbar(hide) {
static ABM_SETSTATE := 0xA, ABS_AUTOHIDE := 0x1, ABS_ALWAYSONTOP := 0x2
if (hide is not integer)
hide := !hide
VarSetCapacity(APPBARDATA, size := 2 * A_PtrSize + 2 * 4 + 16 + A_PtrSize, 0)
NumPut(size, APPBARDATA)
NumPut(WinExist("ahk_class Shell_TrayWnd"), APPBARDATA, A_PtrSize)
NumPut(hide ? ABS_AUTOHIDE : ABS_ALWAYSONTOP, APPBARDATA, size - A_PtrSize)
DllCall("Shell32\SHAppBarMessage", UInt, ABM_SETSTATE, Ptr, &APPBARDATA)
}
;─────────────────────────────────────────[Function to Open default browser]─────────────────────────────────────────
; Original inspiration from:
; https://www.autohotkey.com/board/topic/67330-how-to-open-default-web-browser/
; Thanks :)
DefaultBrowser() {
RegRead, BrowserKeyName, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.html\UserChoice, Progid
RegRead, BrowserFullCommand, HKEY_CLASSES_ROOT, %BrowserKeyName%\shell\open\command
StringGetPos, pos, BrowserFullCommand, ",,1
pos := --pos
StringMid, BrowserPathandEXE, BrowserFullCommand, 2, %pos%
Return BrowserPathandEXE
}
;─────────────────────────────────────────[Function to Hide/Show Desktop Icons]─────────────────────────────────────────
; Original inspiration from:
; https://www.autohotkey.com/board/topic/67330-how-to-open-default-web-browser/
; Thanks :)
DesktopIcons( Show:=-1 ) ; By SKAN for ahk/ah2 on D35D/D495 @ tiny.cc/desktopicons
{
Local hProgman := WinExist("ahk_class WorkerW", "FolderView") ? WinExist()
: WinExist("ahk_class Progman", "FolderView")
Local hShellDefView := DllCall("user32.dll\GetWindow", "ptr",hProgman, "int",5, "ptr")
Local hSysListView := DllCall("user32.dll\GetWindow", "ptr",hShellDefView, "int",5, "ptr")
If ( DllCall("user32.dll\IsWindowVisible", "ptr",hSysListView) != Show )
DllCall("user32.dll\SendMessage", "ptr",hShellDefView, "ptr",0x111, "ptr",0x7402, "ptr",0)
}
ReloadScript:
ToolTip, Reloading Script... Please wait.
Sleep, 500
Reload
return
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return
GetHotkey(keybind) {
StringSplit, result, keybind, #
return Trim(result1)
}
GetHotkeyDisplay(keybind) {
StringSplit, result, keybind, #
return Trim(result2)
}
~Esc::
if (currentActiveMenu != "") {
Gui, Destroy
currentActiveMenu := ""
}
return
GuiClose:
Gui, Destroy
currentActiveMenu := ""
return