DuskDegree9667

Desktop.ahk

Oct 4th, 2026
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Autohotkey 10.89 KB | Software | 0 0
  1. #Requires AutoHotkey v2.0
  2. #SingleInstance Force
  3. A_WorkingDir := A_ScriptDir
  4. A_MaxHotkeysPerInterval := 500
  5. InstallKeybdHook()
  6. InstallMouseHook()
  7.  
  8. ; ==============================================================================
  9. ; Globals & State
  10. ; ==============================================================================
  11. global Layer2 := false
  12. global keyboardBlocked := false
  13.  
  14. ; ==============================================================================
  15. ; Layer Toggle (F10)
  16. ; ==============================================================================
  17. $F10:: {
  18.     global Layer2
  19.     KeyWait("F10")
  20.     Layer2 := !Layer2
  21.     if (Layer2) {
  22.         SetTimer(UpdateTooltip2, 50)
  23.     } else {
  24.         SetTimer(UpdateTooltip2, 0)
  25.         SetTimer(UpdateTooltip1, 50)
  26.         SetTimer(RemoveTooltip, -1000)
  27.     }
  28. }
  29.  
  30. UpdateTooltip1() {
  31.     MouseGetPos(&MouseX, &MouseY)
  32.     ToolTip("Layer 1 is active", MouseX + 15, MouseY + 15)
  33. }
  34.  
  35. UpdateTooltip2() {
  36.     global Layer2
  37.     if (Layer2) {
  38.         MouseGetPos(&MouseX, &MouseY)
  39.         ToolTip("Layer 2 is active", MouseX + 15, MouseY + 15)
  40.     }
  41. }
  42.  
  43. RemoveTooltip() {
  44.     SetTimer(UpdateTooltip1, 0)
  45.     ToolTip()
  46. }
  47.  
  48. ; ==============================================================================
  49. ; File Explorer Hotkeys
  50. ; ==============================================================================
  51. #HotIf WinActive("ahk_class CabinetWClass ahk_exe explorer.exe")
  52.  
  53. ; Toggle File Explorer Hidden Files
  54. !+h:: {
  55.     if (!A_IsAdmin) {
  56.         Run('*RunAs "' A_ScriptFullPath '"')
  57.         ExitApp()
  58.     }
  59.     try {
  60.         hidden := RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "Hidden")
  61.     } catch {
  62.         hidden := 2
  63.     }
  64.  
  65.     ; 1 = Show hidden, 2 = Do not show
  66.     RegWrite(hidden == 1 ? 2 : 1, "REG_DWORD", "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced",
  67.         "Hidden")
  68.  
  69.     windows := WinGetList("ahk_exe explorer.exe")
  70.     for id in windows {
  71.         try ControlSend("{F5}", "DirectUIHWND2", id)
  72.     }
  73. }
  74.  
  75. #HotIf
  76.  
  77. ; ==============================================================================
  78. ; General Hotkeys
  79. ; ==============================================================================
  80. ; Toggle Task Manager Restart for PowerToys Light Switch
  81. ^+#d:: {
  82.     static lastPressed := 0
  83.     if (A_TickCount - lastPressed < 1000) {
  84.         return
  85.     }
  86.     KeyWait("d")
  87.     Send('^+#{d}')
  88.     Sleep(5000)
  89.  
  90.     winList := WinGetList("ahk_exe librewolf.exe")
  91.     for id in winList {
  92.         if WinExist("ahk_id " id) && WinGetMinMax(id) != -1 {
  93.             Sleep(5000)
  94.             WinActivate(id)
  95.             WinWaitActive("ahk_id " id)
  96.             Send("!+d")
  97.         }
  98.     }
  99.  
  100.     if ProcessExist("Taskmgr.exe") {
  101.         ProcessClose("Taskmgr.exe")
  102.         Sleep(1000)
  103.         Run("Taskmgr.exe")
  104.     }
  105.     lastPressed := A_TickCount
  106. }
  107.  
  108. F8::#n
  109. !F8::^+b
  110. F9::^Tab
  111.  
  112. !F9:: {
  113.     iniPath := A_ScriptDir . "\INI Files\PrimaryDisplayId.ini"
  114.     displayId1 := "1"
  115.     displayId2 := "2"
  116.  
  117.     currentId := IniRead(iniPath, "Settings", "PrimaryDisplayId", displayId1)
  118.     newId := (currentId = displayId1) ? displayId2 : displayId1
  119.     IniWrite(newId, iniPath, "Settings", "PrimaryDisplayId")
  120.  
  121.     Run('powershell.exe -NoProfile -Command "Set-DisplayPrimary -DisplayId ' newId '"', , "Hide")
  122.     TrayTip('Profile Manager', 'Primary display set to: ' newId, 1)
  123.  
  124.     KeyWait("F9")
  125.     KeyWait("Alt")
  126. }
  127.  
  128. ; ==============================================================================
  129. ; Layered Macro Keys
  130. ; ==============================================================================
  131.  
  132. ; --- F11 ---
  133. #HotIf !Layer2
  134. F11:: {
  135.     Send("{Left}{Enter}")
  136.     KeyWait("F11")
  137. }
  138. #HotIf Layer2
  139. F11:: {
  140.     Run("control.exe")
  141.     KeyWait("F11")
  142. }
  143.  
  144. ; --- F12 ---
  145. #HotIf
  146. F12:: {
  147.     KeyWait("F12")
  148.     if (A_TimeSinceThisHotkey > 500) {
  149.         Send("{F12}")
  150.     }
  151. }
  152. #HotIf !Layer2
  153. $!F12:: {
  154.     Run('"C:\Users\user\Apps & Utilities\Custom Scripts - Visual Basic & Shell\CycleAudioDevices.bat"')
  155.     KeyWait("F12")
  156. }
  157. #HotIf Layer2
  158. $!F12:: {
  159.     Run("ms-settings:apps-volume")
  160.     KeyWait("F12")
  161. }
  162.  
  163. ; --- F13 ---
  164. #HotIf !Layer2
  165. F13:: {
  166.     SendInput("{Blind}^{c}")
  167.     KeyWait("F13")
  168. }
  169. #HotIf Layer2
  170. F13:: {
  171.     if !ProcessExist("LCore.exe") {
  172.         Run('"C:\Program Files\Logitech Gaming Software\LCore.exe"', , "Max")
  173.         MoveWindowToMouseBounds("ahk_exe LCore.exe")
  174.     } else if WinActive("ahk_exe LCore.exe") {
  175.         ProcessClose("LCore.exe")
  176.     } else {
  177.         try {
  178.             WinActivate("ahk_exe LCore.exe")
  179.             MoveWindowToMouseBounds("ahk_exe LCore.exe")
  180.         } catch TargetError {
  181.             Run('"C:\Program Files\Logitech Gaming Software\LCore.exe"', , "Max")
  182.             MoveWindowToMouseBounds("ahk_exe LCore.exe")
  183.         }
  184.     }
  185.     KeyWait("F13")
  186. }
  187.  
  188. ; --- F14 ---
  189. #HotIf !Layer2
  190. F14:: {
  191.     KeyWait("F14")
  192.     Send("{LAlt Down}")
  193.     Sleep(85)
  194.     Send("{Right}")
  195.     Sleep(85)
  196.     Send("{LAlt Up}")
  197.     Sleep(85)
  198. }
  199. #HotIf Layer2
  200. F14:: {
  201.     Send("^{Home}")
  202.     KeyWait("F14")
  203. }
  204.  
  205. ; --- F15 ---
  206. #HotIf !Layer2
  207. F15:: {
  208.     SendInput("{Blind}^{x}")
  209.     KeyWait("F15")
  210. }
  211. #HotIf Layer2
  212. F15:: {
  213.     Run("eventvwr.msc")
  214.     KeyWait("F15")
  215. }
  216.  
  217. ; --- F16 ---
  218. #HotIf !Layer2
  219. F16:: {
  220.     SendInput("{Blind}^v")
  221.     KeyWait("F16")
  222. }
  223. #HotIf Layer2
  224. F16:: {
  225.     Run('"C:\Users\user\Apps & Utilities\NirCmd\nircmd.exe" monitor off')
  226.     KeyWait("F16")
  227. }
  228.  
  229. ; --- F17 ---
  230. #HotIf !Layer2
  231. F17:: {
  232.     SendInput("{Blind}^{Tab}")
  233.     KeyWait("F17")
  234. }
  235. #HotIf Layer2
  236. F17:: {
  237.     Send("{PgUp}")
  238.     KeyWait("F17")
  239. }
  240.  
  241. ; --- F18 ---
  242. #HotIf !Layer2
  243. *F18:: {
  244.     Send("{Delete}")
  245.     Sleep(500)
  246.     while GetKeyState("F18", "P") {
  247.         Send("{Delete}")
  248.         Sleep(50)
  249.     }
  250. }
  251. #HotIf Layer2
  252. *F18:: {
  253.     Run("resmon.exe")
  254.     KeyWait("F18")
  255. }
  256.  
  257. ; --- F19 ---
  258. #HotIf !Layer2
  259. F19:: {
  260.     Send("{F5}")
  261.     KeyWait("F19")
  262. }
  263. #HotIf Layer2
  264. F19:: {
  265.     Send("!p")
  266.     KeyWait("F19")
  267. }
  268.  
  269. ; --- F20 ---
  270. #HotIf !Layer2
  271. F20:: {
  272.     SendInput("{Blind}^+{Tab}")
  273.     KeyWait("F20")
  274. }
  275. #HotIf Layer2
  276. F20:: {
  277.     Send("{PgDn}")
  278.     KeyWait("F20")
  279. }
  280.  
  281. ; --- F21 ---
  282. #HotIf !Layer2
  283. F21:: {
  284.     Send("{LControl Down}{w Down}")
  285.     Sleep(85)
  286.     Send("{LControl Up}{w Up}")
  287.     Sleep(85)
  288. }
  289. #HotIf Layer2
  290. F21:: {
  291.     Run("services.msc")
  292. }
  293.  
  294. ; --- F22 ---
  295. #HotIf !Layer2
  296. F22:: {
  297.     Send("{Enter}")
  298. }
  299. #HotIf Layer2
  300. F22:: {
  301.     KeyWait("F22")
  302.     Run('"C:\Users\user\Documents"')
  303. }
  304.  
  305. ; --- F23 ---
  306. #HotIf !Layer2
  307. F23:: {
  308.     KeyWait("F23")
  309.     Send("{LAlt Down}")
  310.     Sleep(85)
  311.     Send("{Left}")
  312.     Sleep(85)
  313.     Send("{LAlt Up}")
  314.     Sleep(85)
  315. }
  316. #HotIf Layer2
  317. F23:: {
  318.     Send("^{End}")
  319.     KeyWait("F23")
  320. }
  321.  
  322. ; --- F24 ---
  323. #HotIf !Layer2
  324. F24:: {
  325.     Send("^+t")
  326.     KeyWait("F24")
  327. }
  328. #HotIf Layer2
  329. F24:: {
  330.     Run("taskmgr.exe")
  331.     KeyWait("F24")
  332. }
  333.  
  334. ; --- RButton ---
  335. ; By excluding !Layer2 here, RButton retains its native Windows behavior in Layer 1, enabling normal right click and dragging.
  336. #HotIf Layer2
  337. RButton:: {
  338.     try {
  339.         if (WinGetProcessName("A") = "explorer.exe") {
  340.             WinClose("A")
  341.         } else {
  342.             ProcessClose(WinGetPID("A"))
  343.         }
  344.     }
  345.     KeyWait("RButton")
  346. }
  347. #HotIf
  348.  
  349. ; ==============================================================================
  350. ; Helper Functions
  351. ; ==============================================================================
  352. MoveWindowToMouseBounds(winTitle) {
  353.     if !WinWait(winTitle, , 5)
  354.         return
  355.     if WinGetMinMax(winTitle) == 1
  356.         WinRestore(winTitle)
  357.     WinActivate(winTitle)
  358.     if !WinWaitActive(winTitle, , 3)
  359.         return
  360.  
  361.     SavedCoordMode := A_CoordModeMouse
  362.     CoordMode("Mouse", "Screen")
  363.     MouseGetPos(&mX, &mY)
  364.     CoordMode("Mouse", SavedCoordMode)
  365.  
  366.     WinGetPos(&wX, &wY, &wW, &wH, winTitle)
  367.  
  368.     mCount := MonitorGetCount()
  369.     targetMonitor := MonitorGetPrimary()
  370.     loop mCount {
  371.         MonitorGet(A_Index, &L, &T, &R, &B)
  372.         if (mX >= L && mX <= R && mY >= T && mY <= B) {
  373.             targetMonitor := A_Index
  374.             break
  375.         }
  376.     }
  377.  
  378.     MonitorGetWorkArea(targetMonitor, &WL, &WT, &WR, &WB)
  379.  
  380.     newX := mX
  381.     newY := mY
  382.  
  383.     if (newX + wW > WR)
  384.         newX := WR - wW
  385.     if (newX < WL)
  386.         newX := WL
  387.  
  388.     if (newY + wH > WB)
  389.         newY := WB - wH
  390.     if (newY < WT)
  391.         newY := WT
  392.  
  393.     WinMove(newX, newY, wW, wH, winTitle)
  394. }
  395.  
  396. ; ==============================================================================
  397. ; Infinite Scrolling with Mouse Wheel
  398. ; ==============================================================================
  399. *WheelUp:: Scroll(-1)
  400. *WheelDown:: Scroll(1)
  401.  
  402. Scroll(Direction) {
  403.     static scrollCount := 0, level := 1, maxLevel := 15, timeout := 350, levelTickCount := 0
  404.         , initialKeyStates := 0, scrollingState := 0, flick := 0, wheelDir := ""
  405.  
  406.     if (level < maxLevel && ++scrollCount >= 3) {
  407.         flick := (A_TickCount - levelTickCount < 40)
  408.         levelTickCount := A_TickCount
  409.         level++
  410.         scrollCount := 1
  411.     }
  412.  
  413.     wheelDir := (Direction = -1 ? "WheelUp" : "WheelDown")
  414.  
  415.     if (A_PriorHotkey = A_ThisHotkey && A_TimeSincePriorHotkey < timeout && level > 1) {
  416.         Send("{Blind}{" wheelDir " " level "}")
  417.         if (flick) {
  418.             initialKeyStates := GetKeyState("Shift", "P") . GetKeyState("MButton", "P") . GetKeyState("Space", "P") .
  419.             GetKeyState("Ctrl", "P") . GetKeyState("Alt", "P")
  420.             scrollingState := 1
  421.             SetTimer(AutoScroll, 30)
  422.         }
  423.     } else {
  424.         if (scrollingState)
  425.             scrollingState := 0
  426.         else
  427.             Send("{Blind}{" wheelDir "}")
  428.         level := 1
  429.     }
  430.  
  431.     AutoScroll() {
  432.         if (level = 1
  433.             || GetKeyState("Shift", "P") . GetKeyState("MButton", "P") . GetKeyState("Space", "P") . GetKeyState("Ctrl",
  434.                 "P") . GetKeyState("Alt", "P") != initialKeyStates
  435.             || (DllCall("GetAsyncKeyState", "int", 0x01) & 0x8000)
  436.             || (DllCall("GetAsyncKeyState", "int", 0x02) & 0x8000)
  437.             || !scrollingState
  438.             || A_PriorHotKey != A_ThisHotkey) {
  439.             scrollingState := 0
  440.             SetTimer(AutoScroll, 0)
  441.         } else {
  442.             Send("{Blind}{" wheelDir " " level "}")
  443.         }
  444.     }
  445. }
  446.  
  447. ; ==============================================================================
  448. ; Keyboard Lock for Cleaning
  449. ; ==============================================================================
  450. func_BlockKeyboard(state) {
  451.     loop 512 {
  452.         Key := Format("SC{:X}", A_Index)
  453.         try {
  454.             if (state = "On")
  455.                 Hotkey(Key, do_nothing, "On")
  456.             else
  457.                 Hotkey(Key, do_nothing, "Off")
  458.         }
  459.     }
  460. }
  461.  
  462. do_nothing(ThisHotkey) {
  463.     return
  464. }
  465.  
  466. Insert & Home:: func_BlockKeyboard("On")
  467. Insert & End:: func_BlockKeyboard("Off")
Advertisement
Add Comment
Please, Sign In to add comment