Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Requires AutoHotkey v2.0
- #SingleInstance Force
- A_WorkingDir := A_ScriptDir
- A_MaxHotkeysPerInterval := 500
- InstallKeybdHook()
- InstallMouseHook()
- ; ==============================================================================
- ; Globals & State
- ; ==============================================================================
- global Layer2 := false
- global keyboardBlocked := false
- ; ==============================================================================
- ; Layer Toggle (F10)
- ; ==============================================================================
- $F10:: {
- global Layer2
- KeyWait("F10")
- Layer2 := !Layer2
- if (Layer2) {
- SetTimer(UpdateTooltip2, 50)
- } else {
- SetTimer(UpdateTooltip2, 0)
- SetTimer(UpdateTooltip1, 50)
- SetTimer(RemoveTooltip, -1000)
- }
- }
- UpdateTooltip1() {
- MouseGetPos(&MouseX, &MouseY)
- ToolTip("Layer 1 is active", MouseX + 15, MouseY + 15)
- }
- UpdateTooltip2() {
- global Layer2
- if (Layer2) {
- MouseGetPos(&MouseX, &MouseY)
- ToolTip("Layer 2 is active", MouseX + 15, MouseY + 15)
- }
- }
- RemoveTooltip() {
- SetTimer(UpdateTooltip1, 0)
- ToolTip()
- }
- ; ==============================================================================
- ; File Explorer Hotkeys
- ; ==============================================================================
- #HotIf WinActive("ahk_class CabinetWClass ahk_exe explorer.exe")
- ; Toggle File Explorer Hidden Files
- !+h:: {
- if (!A_IsAdmin) {
- Run('*RunAs "' A_ScriptFullPath '"')
- ExitApp()
- }
- try {
- hidden := RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "Hidden")
- } catch {
- hidden := 2
- }
- ; 1 = Show hidden, 2 = Do not show
- RegWrite(hidden == 1 ? 2 : 1, "REG_DWORD", "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced",
- "Hidden")
- windows := WinGetList("ahk_exe explorer.exe")
- for id in windows {
- try ControlSend("{F5}", "DirectUIHWND2", id)
- }
- }
- #HotIf
- ; ==============================================================================
- ; General Hotkeys
- ; ==============================================================================
- ; Toggle Task Manager Restart for PowerToys Light Switch
- ^+#d:: {
- static lastPressed := 0
- if (A_TickCount - lastPressed < 1000) {
- return
- }
- KeyWait("d")
- Send('^+#{d}')
- Sleep(5000)
- winList := WinGetList("ahk_exe librewolf.exe")
- for id in winList {
- if WinExist("ahk_id " id) && WinGetMinMax(id) != -1 {
- Sleep(5000)
- WinActivate(id)
- WinWaitActive("ahk_id " id)
- Send("!+d")
- }
- }
- if ProcessExist("Taskmgr.exe") {
- ProcessClose("Taskmgr.exe")
- Sleep(1000)
- Run("Taskmgr.exe")
- }
- lastPressed := A_TickCount
- }
- F8::#n
- !F8::^+b
- F9::^Tab
- !F9:: {
- iniPath := A_ScriptDir . "\INI Files\PrimaryDisplayId.ini"
- displayId1 := "1"
- displayId2 := "2"
- currentId := IniRead(iniPath, "Settings", "PrimaryDisplayId", displayId1)
- newId := (currentId = displayId1) ? displayId2 : displayId1
- IniWrite(newId, iniPath, "Settings", "PrimaryDisplayId")
- Run('powershell.exe -NoProfile -Command "Set-DisplayPrimary -DisplayId ' newId '"', , "Hide")
- TrayTip('Profile Manager', 'Primary display set to: ' newId, 1)
- KeyWait("F9")
- KeyWait("Alt")
- }
- ; ==============================================================================
- ; Layered Macro Keys
- ; ==============================================================================
- ; --- F11 ---
- #HotIf !Layer2
- F11:: {
- Send("{Left}{Enter}")
- KeyWait("F11")
- }
- #HotIf Layer2
- F11:: {
- Run("control.exe")
- KeyWait("F11")
- }
- ; --- F12 ---
- #HotIf
- F12:: {
- KeyWait("F12")
- if (A_TimeSinceThisHotkey > 500) {
- Send("{F12}")
- }
- }
- #HotIf !Layer2
- $!F12:: {
- Run('"C:\Users\user\Apps & Utilities\Custom Scripts - Visual Basic & Shell\CycleAudioDevices.bat"')
- KeyWait("F12")
- }
- #HotIf Layer2
- $!F12:: {
- Run("ms-settings:apps-volume")
- KeyWait("F12")
- }
- ; --- F13 ---
- #HotIf !Layer2
- F13:: {
- SendInput("{Blind}^{c}")
- KeyWait("F13")
- }
- #HotIf Layer2
- F13:: {
- if !ProcessExist("LCore.exe") {
- Run('"C:\Program Files\Logitech Gaming Software\LCore.exe"', , "Max")
- MoveWindowToMouseBounds("ahk_exe LCore.exe")
- } else if WinActive("ahk_exe LCore.exe") {
- ProcessClose("LCore.exe")
- } else {
- try {
- WinActivate("ahk_exe LCore.exe")
- MoveWindowToMouseBounds("ahk_exe LCore.exe")
- } catch TargetError {
- Run('"C:\Program Files\Logitech Gaming Software\LCore.exe"', , "Max")
- MoveWindowToMouseBounds("ahk_exe LCore.exe")
- }
- }
- KeyWait("F13")
- }
- ; --- F14 ---
- #HotIf !Layer2
- F14:: {
- KeyWait("F14")
- Send("{LAlt Down}")
- Sleep(85)
- Send("{Right}")
- Sleep(85)
- Send("{LAlt Up}")
- Sleep(85)
- }
- #HotIf Layer2
- F14:: {
- Send("^{Home}")
- KeyWait("F14")
- }
- ; --- F15 ---
- #HotIf !Layer2
- F15:: {
- SendInput("{Blind}^{x}")
- KeyWait("F15")
- }
- #HotIf Layer2
- F15:: {
- Run("eventvwr.msc")
- KeyWait("F15")
- }
- ; --- F16 ---
- #HotIf !Layer2
- F16:: {
- SendInput("{Blind}^v")
- KeyWait("F16")
- }
- #HotIf Layer2
- F16:: {
- Run('"C:\Users\user\Apps & Utilities\NirCmd\nircmd.exe" monitor off')
- KeyWait("F16")
- }
- ; --- F17 ---
- #HotIf !Layer2
- F17:: {
- SendInput("{Blind}^{Tab}")
- KeyWait("F17")
- }
- #HotIf Layer2
- F17:: {
- Send("{PgUp}")
- KeyWait("F17")
- }
- ; --- F18 ---
- #HotIf !Layer2
- *F18:: {
- Send("{Delete}")
- Sleep(500)
- while GetKeyState("F18", "P") {
- Send("{Delete}")
- Sleep(50)
- }
- }
- #HotIf Layer2
- *F18:: {
- Run("resmon.exe")
- KeyWait("F18")
- }
- ; --- F19 ---
- #HotIf !Layer2
- F19:: {
- Send("{F5}")
- KeyWait("F19")
- }
- #HotIf Layer2
- F19:: {
- Send("!p")
- KeyWait("F19")
- }
- ; --- F20 ---
- #HotIf !Layer2
- F20:: {
- SendInput("{Blind}^+{Tab}")
- KeyWait("F20")
- }
- #HotIf Layer2
- F20:: {
- Send("{PgDn}")
- KeyWait("F20")
- }
- ; --- F21 ---
- #HotIf !Layer2
- F21:: {
- Send("{LControl Down}{w Down}")
- Sleep(85)
- Send("{LControl Up}{w Up}")
- Sleep(85)
- }
- #HotIf Layer2
- F21:: {
- Run("services.msc")
- }
- ; --- F22 ---
- #HotIf !Layer2
- F22:: {
- Send("{Enter}")
- }
- #HotIf Layer2
- F22:: {
- KeyWait("F22")
- Run('"C:\Users\user\Documents"')
- }
- ; --- F23 ---
- #HotIf !Layer2
- F23:: {
- KeyWait("F23")
- Send("{LAlt Down}")
- Sleep(85)
- Send("{Left}")
- Sleep(85)
- Send("{LAlt Up}")
- Sleep(85)
- }
- #HotIf Layer2
- F23:: {
- Send("^{End}")
- KeyWait("F23")
- }
- ; --- F24 ---
- #HotIf !Layer2
- F24:: {
- Send("^+t")
- KeyWait("F24")
- }
- #HotIf Layer2
- F24:: {
- Run("taskmgr.exe")
- KeyWait("F24")
- }
- ; --- RButton ---
- ; By excluding !Layer2 here, RButton retains its native Windows behavior in Layer 1, enabling normal right click and dragging.
- #HotIf Layer2
- RButton:: {
- try {
- if (WinGetProcessName("A") = "explorer.exe") {
- WinClose("A")
- } else {
- ProcessClose(WinGetPID("A"))
- }
- }
- KeyWait("RButton")
- }
- #HotIf
- ; ==============================================================================
- ; Helper Functions
- ; ==============================================================================
- MoveWindowToMouseBounds(winTitle) {
- if !WinWait(winTitle, , 5)
- return
- if WinGetMinMax(winTitle) == 1
- WinRestore(winTitle)
- WinActivate(winTitle)
- if !WinWaitActive(winTitle, , 3)
- return
- SavedCoordMode := A_CoordModeMouse
- CoordMode("Mouse", "Screen")
- MouseGetPos(&mX, &mY)
- CoordMode("Mouse", SavedCoordMode)
- WinGetPos(&wX, &wY, &wW, &wH, winTitle)
- mCount := MonitorGetCount()
- targetMonitor := MonitorGetPrimary()
- loop mCount {
- MonitorGet(A_Index, &L, &T, &R, &B)
- if (mX >= L && mX <= R && mY >= T && mY <= B) {
- targetMonitor := A_Index
- break
- }
- }
- MonitorGetWorkArea(targetMonitor, &WL, &WT, &WR, &WB)
- newX := mX
- newY := mY
- if (newX + wW > WR)
- newX := WR - wW
- if (newX < WL)
- newX := WL
- if (newY + wH > WB)
- newY := WB - wH
- if (newY < WT)
- newY := WT
- WinMove(newX, newY, wW, wH, winTitle)
- }
- ; ==============================================================================
- ; Infinite Scrolling with Mouse Wheel
- ; ==============================================================================
- *WheelUp:: Scroll(-1)
- *WheelDown:: Scroll(1)
- Scroll(Direction) {
- static scrollCount := 0, level := 1, maxLevel := 15, timeout := 350, levelTickCount := 0
- , initialKeyStates := 0, scrollingState := 0, flick := 0, wheelDir := ""
- if (level < maxLevel && ++scrollCount >= 3) {
- flick := (A_TickCount - levelTickCount < 40)
- levelTickCount := A_TickCount
- level++
- scrollCount := 1
- }
- wheelDir := (Direction = -1 ? "WheelUp" : "WheelDown")
- if (A_PriorHotkey = A_ThisHotkey && A_TimeSincePriorHotkey < timeout && level > 1) {
- Send("{Blind}{" wheelDir " " level "}")
- if (flick) {
- initialKeyStates := GetKeyState("Shift", "P") . GetKeyState("MButton", "P") . GetKeyState("Space", "P") .
- GetKeyState("Ctrl", "P") . GetKeyState("Alt", "P")
- scrollingState := 1
- SetTimer(AutoScroll, 30)
- }
- } else {
- if (scrollingState)
- scrollingState := 0
- else
- Send("{Blind}{" wheelDir "}")
- level := 1
- }
- AutoScroll() {
- if (level = 1
- || GetKeyState("Shift", "P") . GetKeyState("MButton", "P") . GetKeyState("Space", "P") . GetKeyState("Ctrl",
- "P") . GetKeyState("Alt", "P") != initialKeyStates
- || (DllCall("GetAsyncKeyState", "int", 0x01) & 0x8000)
- || (DllCall("GetAsyncKeyState", "int", 0x02) & 0x8000)
- || !scrollingState
- || A_PriorHotKey != A_ThisHotkey) {
- scrollingState := 0
- SetTimer(AutoScroll, 0)
- } else {
- Send("{Blind}{" wheelDir " " level "}")
- }
- }
- }
- ; ==============================================================================
- ; Keyboard Lock for Cleaning
- ; ==============================================================================
- func_BlockKeyboard(state) {
- loop 512 {
- Key := Format("SC{:X}", A_Index)
- try {
- if (state = "On")
- Hotkey(Key, do_nothing, "On")
- else
- Hotkey(Key, do_nothing, "Off")
- }
- }
- }
- do_nothing(ThisHotkey) {
- return
- }
- Insert & Home:: func_BlockKeyboard("On")
- Insert & End:: func_BlockKeyboard("Off")
Advertisement
Add Comment
Please, Sign In to add comment