Autohotkey ahk power control script etc/

#InstallKeybdHook
#SingleInstance force
SetWorkingDir %A_ScriptDir%
#include group2.ahk
#include VA.ahk
#include VD.ahk
Menu, Tray, Icon, p.ico

; Functions
ChangeDisplayFrequency(Frequency) {
    VarSetCapacity(DEVMODE, 156, 0)
    NumPut(156, DEVMODE, 36, "UShort")
    DllCall("EnumDisplaySettingsA", "Ptr", 0, "UInt", -1, "Ptr", &DEVMODE)
    NumPut(0x400000, DEVMODE, 40)
    NumPut(Frequency, DEVMODE, 120, "UInt")
    Return DllCall("ChangeDisplaySettingsA", "Ptr", &DEVMODE, "UInt", 0)
}

RunFoobar(cmd, path := "C:\Program Files (x86)\foobar2000\foobar2000.exe") {
    Run %path% %cmd%
    Sleep 1000
}

ToggleWindow(exe1, exe2) {
    IfWinActive % "ahk_exe " exe1
        WinActivate % "ahk_exe " exe2
    else
        WinActivate % "ahk_exe " exe1
}

OpenOrActivate(path, title, maximize := 1) {
    IfWinExist %title%
        WinActivate %title%
    else {
        Run %path%
        WinWait %title%
        if (maximize)
            WinMaximize
    }
}

RunRandom(file, prefix := "Run", suffix := "", browser := "") {
    FileRead, content, %file%
    if (ErrorLevel) {
        MsgBox, Could not read %file%
        return
    }
    Sort, content, Random
    line := Trim(SubStr(content, 1, InStr(content, "`r") - 1))
    if (line = "") {
        MsgBox, No valid content found in %file%
        return
    }
    if (prefix = "Send") {
        Send %line%%suffix%
    } else {
        if (browser != "") {
            fullCmd := browser . " """ . line . """"
        } else {
            fullCmd := prefix . " " . line . suffix
        }
        Run %fullCmd%, , UseErrorLevel
        if (ErrorLevel) {
            MsgBox, Failed to run: %fullCmd%
        }
    }
}

SendCmd(console, cmd, clip := 0) {
    IfWinNotExist %console%
        return
    WinActivate %console%
    WinWaitActive %console%, , 2
    if (ErrorLevel)
        return
    Sleep 200
    Send %cmd%
    if (clip)
        Send %Clipboard%
    Send {Enter}
}

SendTime(fmt) {
    FormatTime, time, A_Now, %fmt%
    Send %time%
}

; Autoexecute GUI
Gui -Caption
Gui Add, ListView,, HOTKEY|COMMENT
for i, e in Hotkeys(Hotkeys)
    LV_Add("", e.Hotkey, e.Comment)
LV_ModifyCol()

; Hotkeys with comments
; Hotkeys with comments
#Insert:: ; Suspend all hotkeys
    Suspend
    return

MButton:: ; Preserve default middle click behavior
    Send {MButton down}
    Sleep 1
    Send {MButton up}
    return

MButton & XButton2:: ; Play random track with MButton + XButton2
    RunFoobar("/runcmd=Playback/Random")
    return

MButton & XButton1:: ; Toggle between Firefox and Pale Moon with MButton + XButton1
    ToggleWindow("firefox.exe", "palemoon.exe")
    return

^MButton:: ; Play random track with Ctrl + MButton
    RunFoobar("/runcmd=Playback/Random")
    return

^!WheelUp:: ; Set volume to 0 dB with Ctrl + Alt + WheelUp
    RunFoobar("/runcmd=Playback/Volume/Set to -0 dB")
    return

^!WheelDown:: ; Set volume to -12 dB with Ctrl + Alt + WheelDown
    RunFoobar("/runcmd=Playback/Volume/Set to -12 dB")
    return

+f9:: ; Play/pause alternate foobar2000 with Shift + F9
    Run "D:\foobar2000b\foobar2000.exe" "/playpause"
    return

f9:: ; Play/pause main foobar2000 with F9
    RunFoobar("/playpause")
    return

f10:: ; Previous track in foobar2000 with F10
    RunFoobar("/prev")
    return

f11:: ; Next track in foobar2000 with F11
    RunFoobar("/next")
    return

!6:: ; Toggle Discord Rich Presence in foobar2000 with Alt + 6
    RunFoobar("/runcmd=View/Display Discord Rich Presence")
    return

^XButton2:: ; Play random track with Ctrl + XButton2
    RunFoobar("/runcmd=Playback/Random")
    return

+Volume_Down:: ; Seek back 1 second with Shift + Volume Down
    RunFoobar("/runcmd=Playback/Seek/""Back by 1 second""")
    return

+Volume_Up:: ; Seek ahead 1 second with Shift + Volume Up
    RunFoobar("/runcmd=Playback/Seek/""Ahead by 1 second""")
    return

^Volume_Down:: ; Seek back 10 seconds with Ctrl + Volume Down
    RunFoobar("/runcmd=Playback/Seek/""Back by 10 seconds""")
    return

^Volume_Up:: ; Seek ahead 10 seconds with Ctrl + Volume Up
    RunFoobar("/runcmd=Playback/Seek/""Ahead by 10 seconds""")
    return

appskey & b:: ; Toggle between Betterbird and Thunderbird with AppsKey + B
    ToggleWindow("betterbird.exe", "thunderbird.exe")
    return

appskey & p:: ; Toggle between Notepad++ and VSCodium with AppsKey + P
    ToggleWindow("notepad++.exe", "VSCodium.exe")
    return

appskey & 9:: ; Toggle between WinSCP and FileZilla with AppsKey + 9
    ToggleWindow("WinSCP.exe", "filezilla.exe")
    return

XButton1:: ; Toggle between Renoise and Ableton with XButton1
    ToggleWindow("renoise.exe", "Ableton Live 11 Suite.exe")
    return

numpaddiv:: ; Toggle between foobar2000 and ConEmu with NumpadDiv
    ToggleWindow("foobar2000.exe", "ConEmu64.exe")
    return

numpadmult:: ; Toggle between foobar2000 and Firefox with NumpadMult
    ToggleWindow("foobar2000.exe", "firefox.exe")
    return

appskey & ,:: ; Activate main foobar2000 with AppsKey + ,
    WinActivate ahk_exe C:\Program Files (x86)\foobar2000\foobar2000.exe
    return

appskey & .:: ; Activate alternate foobar2000 with AppsKey + .
    WinActivate ahk_exe D:\foobar2000b\foobar2000.exe
    return

appskey & /:: ; Activate third foobar2000 instance with AppsKey + /
    WinActivate ahk_exe D:\foobar2000c\foobar2000.exe
    return

+NumpadAdd:: ; Activate Renoise with Shift + NumpadAdd
    WinActivate ahk_class Renoise
    return

+NumpadDiv:: ; Activate PHP book with Shift + NumpadDiv
    WinActivate Learning PHP
    return

+NumpadSub:: ; Activate SunVox with Shift + NumpadSub
    WinActivate ahk_class SunDogEngine
    return

+NumpadMult:: ; Set 280Hz and activate Sven Co-op with Shift + NumpadMult
    ChangeDisplayFrequency(280)
    Sleep 100
    WinActivate Sven Co-op
    return

appskey & n:: ; Toggle or tab QOwnNotes with AppsKey + N
    IfWinActive ahk_exe QOwnNotes.exe
        SendInput !{Tab}
    else
        WinActivate ahk_exe QOwnNotes.exe
    Send {Alt Up}{Shift Up}{Ctrl Up}{LWin Up}
    Sleep 100
    return

appskey & f:: ; Toggle or tab Firefox with AppsKey + F
    IfWinActive ahk_exe firefox.exe
        SendInput !{Tab}
    else
        WinActivate ahk_exe firefox.exe
    Send {Alt Up}{Shift Up}{Ctrl Up}{LWin Up}
    Sleep 100
    return

appskey & u:: ; Toggle or tab SumatraPDF with AppsKey + U
    IfWinActive ahk_exe SumatraPDF.exe
        SendInput !{Tab}
    else
        WinActivate ahk_exe SumatraPDF.exe
    Send {Alt Up}{Shift Up}{Ctrl Up}{LWin Up}
    Sleep 100
    return

appskey & r:: ; Toggle or tab Renoise with AppsKey + R
    IfWinActive ahk_exe renoise.exe
        SendInput !{Tab}
    else
        WinActivate ahk_exe renoise.exe
    Send {Alt Up}{Shift Up}{Ctrl Up}{LWin Up}
    Sleep 100
    return

appskey & m:: ; Toggle or tab BowPad with AppsKey + M
    IfWinActive ahk_exe BowPad.exe
        SendInput !{Tab}
    else
        WinActivate ahk_exe BowPad.exe
    Send {Alt Up}{Shift Up}{Ctrl Up}{LWin Up}
    Sleep 100
    return

appskey & k:: ; Toggle or tab KeePass with AppsKey + K
    IfWinActive ahk_exe KeePass.exe
        SendInput !{Tab}
    else
        WinActivate ahk_exe KeePass.exe
    Send {Alt Up}{Shift Up}{Ctrl Up}{LWin Up}
    Sleep 100
    return

appskey & i:: ; Toggle or tab Raspberry Pi console with AppsKey + I
    IfWinActive pi@raspberrypi: ~
        SendInput !{Tab}
    else
        WinActivate pi@raspberrypi: ~
    Send {Alt Up}{Shift Up}{Ctrl Up}{LWin Up}
    Sleep 100
    return

appskey & v:: ; Open or activate Videos folder with AppsKey + V
    OpenOrActivate("D:\vid", "Videos")
    return

appskey & q:: ; Open or activate Pictures folder with AppsKey + Q
    OpenOrActivate("D:\windows\Pictures", "Pictures")
    return

#+e:: ; Open or activate D: drive with Win + Shift + E
    OpenOrActivate("D:\", "HDD (D:)")
    return

#+u:: ; Open or activate AppData folder with Win + Shift + U
    OpenOrActivate("C:\Users\sb\AppData", "AppData")
    return

appskey & 1:: ; Open or activate server folder with AppsKey + 1
    OpenOrActivate("D:\server", "server")
    return

appskey & l:: ; Open or activate Local folder with AppsKey + L
    OpenOrActivate("C:\Users\sb\AppData\Local", "Local")
    return

appskey & `;:: ; Open or activate Roaming folder with AppsKey + ;
    OpenOrActivate("C:\Users\sb\AppData\Roaming", "Roaming")
    return

appskey & c:: ; Open or activate bat folder with AppsKey + C
    OpenOrActivate("D:\bat", "bat")
    return

appskey & t:: ; Open or activate test folder with AppsKey + T
    OpenOrActivate("D:\rex\test", "test")
    return

appskey & g:: ; Open or activate game folder with AppsKey + G
    OpenOrActivate("D:\bat\game", "game")
    return

appskey & h:: ; Open or activate html folder with AppsKey + H
    OpenOrActivate("D:\windows\docs\html", "html")
    return

appskey & a:: ; Open or activate Downloads folder with AppsKey + A
    OpenOrActivate("D:\apps", "Downloads")
    return

!NumpadSub:: ; Set display frequency to 60Hz with Alt + NumpadSub
    ChangeDisplayFrequency(60)
    return

!f1:: ; Set display frequency to 60Hz with Alt + F1
    ChangeDisplayFrequency(60)
    return

!NumpadAdd:: ; Set display frequency to 280Hz with Alt + NumpadAdd
    ChangeDisplayFrequency(280)
    return

!f2:: ; Set display frequency to 280Hz with Alt + F2
    ChangeDisplayFrequency(280)
    return

^#F12:: ; Toggle GUI visibility with Ctrl + Win + F12
    Toggle := !Toggle
    if (Toggle) {
        Gui Show, x0 y0
    } else {
        Gui Destroy
    }
    return

+^p:: ; Copy active Explorer path to clipboard with Shift + Ctrl + P
    Clipboard := GetActiveExplorerPath()
    return

#^f9:: ; Write hotkey list to D:\bat\keys.txt with Win + Ctrl + F9
    FileDelete D:\bat\keys.txt
    for i, e in Hotkeys(Hotkeys)
        FileAppend % e.Hotkey " " e.Comment "`n", D:\bat\keys.txt
    SoundBeep
    return

^!NumpadAdd:: ; Set High Performance mode with Ctrl + Alt + NumpadAdd
    Run C:\Windows\System32\powercfg.exe /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
    TrayTip, Power Control, High Performance mode CHECK SPEAKERS, 20, 17
    return

#!NumpadAdd:: ; Set Balanced mode and run HomeSafe View with Win + Shift + NumpadAdd
    Run C:\Windows\System32\powercfg.exe /setactive 381b4222-f694-41f0-9685-ff5bb260df2e
    FileAppend `n%A_YYYY%-%A_MM%-%A_DD% %A_Hour%:%A_Min%:%A_Sec% balanced`n, power.txt
    Process, Exist, HomeSafe View.exe
    if !ErrorLevel
        Run "C:\Program Files (x86)\swann\HomeSafe View\HomeSafe View.exe"
    TrayTip, Power Control, Balanced mode CHECK SPEAKERS, 20, 17
    return

!#m:: ; Close HomeSafe View, set Power Saver mode, and turn off monitors with Alt + Win + M
    Process, Close, HomeSafe View.exe
    Sleep 2000
    FileAppend `n%A_YYYY%-%A_MM%-%A_DD% %A_Hour%:%A_Min%:%A_Sec% lower`n, power.txt
    Run C:\Windows\System32\powercfg.exe /setactive a1841308-3541-4fab-bc81-f71556f20b4a
    Sleep 1000
    SendMessage 0x112, 0xF170, 2, , Program Manager
    return

#m:: ; Turn off monitors with Win + M
    Sleep 1000
    SendMessage 0x112, 0xF170, 2, , Program Manager
    return

^!f11:: ; Process clipboard and write to ChatSoundsnewFR.txt with Ctrl + Alt + F11
    words := ["buhbye", "faggot2", "fuckoff", "byebye", "goodbye", "mbye", "buhbye", "bbye!", "bye!", "baibai!", "stfu", "mstfu", "stfu!", "stfu10s", "stfub", "fatbitch", "uglymf", "urugly", "retardalert", "retard2", "retard", "urfamilyknows"]
    for i, w in words
        Clipboard := StrReplace(Clipboard, w, "")
    Clipboard := RegExReplace(RegExReplace(Clipboard, "\t", ""), " +", " ")
    Clipboard := StrReplace(Clipboard, "!", "{!}")
    Loop {
        Clipboard := StrReplace(Clipboard, "`r`n`r`n", "`r`n", Count)
        if (Count = 0)
            Break
    }
    FileOpen("D:\bat\game\ChatSoundsnewFR.txt", "w").Write(Clipboard).Close()
    Run "C:\cygwin64\bin\mintty.exe" -i /Cygwin-Terminal.ico -e /usr/bin/bash /cygdrive/d/bat/csfix.sh
    return

^+!d:: ; Paste full timestamp with Shift + Ctrl + Alt + D
    SendTime("dddd MMM dd, yyyy hh:mm:ss tt")
    return

!#t:: ; Paste compact timestamp with Alt + Win + T
    SendTime("yyyy MM/dd HH:mm:s")
    return

!#y:: ; Paste date with Alt + Win + Y
    SendTime("yyyy MM dd")
    return

!2:: ; Paste hyphenated date with Alt + 2
    SendTime("yyyy-MM-dd")
    return

^+!f:: ; Paste date without time with Shift + Ctrl + Alt + F
    SendTime("dddd MMM dd, yyyy")
    return

^+!h:: ; Paste time and day with Shift + Ctrl + Alt + H
    FormatTime, t, A_Now, hh:mm tt dddd
    Send last modified %t%
    return

^+!g:: ; Paste formatted ChatSounds notice with Shift + Ctrl + Alt + G
    FormatTime, t, A_Now, dddd MMM dd, yyyy hh:mm tt
    Send last modified %t% EDT (UTC-4){Enter}The majority of these ChatSounds are user submitted and do not Reflect the Views of Bsmesh KING{Enter}Disk space is limited, consider donating if you submit a ton of ChatSounds https://kingsc.net/donate
    return

!#r:: ; Paste Reddit RSS feed with Alt + Win + R
    Send https://www.reddit.com/r/%Clipboard%
    return

f7:: ; Copy Edge URL and title with F7
    WinGetActiveTitle, t
    url := GetURL("Edge")
    Clipboard := t " https://" url
    StringTrimRight, Clipboard, Clipboard, 8
    return

!f3:: ; Ignore JOINS PARTS QUITS NICKS for irssi channel name in Clipboard
    Send /ignore -channels {#}^+{Insert} * JOINS PARTS QUITS NICKS
    return

!w:: ; Wrap clipboard in double quotes with Alt + W
    Send ^x
    Sleep 100
    ClipWait
    Clipboard := """" Clipboard """"
    Sleep 100
    ClipWait
    Send ^v
    return

^+!v:: ; Wrap clipboard in single quotes with Shift + Ctrl + Alt + V
    Clipboard := "'" Clipboard "'"
    Sleep 100
    ClipWait
    Send ^v
    return

^+!b:: ; Wrap clipboard in double quotes with Shift + Ctrl + Alt + B
    Clipboard := """" Clipboard """"
    Sleep 100
    ClipWait
    Send ^v
    return

^+!f12:: ; Empty Recycle Bin with Shift + Ctrl + Alt + F12
    FileRecycleEmpty
    TrayTip, Recycle Bin, Bin emptied, 20, 17
    return

appskey & 2:: ; Open Sound settings with AppsKey + 2
    OpenOrActivate("mmsys.cpl", "Sound", 0)
    return

^#t:: ; Toggle AlwaysOnTop with Ctrl + Win + T
    WinSet AlwaysOnTop, Toggle, A
    SplashImage,, B w%A_ScreenWidth% h%A_ScreenHeight% cwBlack NA
    Sleep 50
    SplashImage, off
    return

^+v:: ; Remove newlines from clipboard with Shift + Ctrl + V
    StringReplace, Clipboard, Clipboard, `r`n, , All
    Send ^v
    return

^!#pause:: ; Block keyboard and mouse input with Ctrl + Alt + Win + Pause
    BlockInput on
    return

appskey & pause:: ; Unblock input with AppsKey + Pause
    BlockInput off
    Send {Alt Up}{Shift Up}{Ctrl Up}{LWin Up}
    return

^f7:: ; Press 'a' every 800ms for 1500 iterations with Ctrl + F7
    Loop 1500 {
        Send a
        Sleep 800
    }
    return

#f:: ; Random mouse wheel in IrfanView with Win + F
    Random, r, 1, 658
    Random, t, 0, 1
    WinActivate ahk_class IrfanView
    WinWaitActive ahk_class IrfanView
    if (t = 1)
        Click WheelDown %r%
    else
        Click WheelUp %r%
    return

!#f:: ; Continuous random wheel with Alt + Win + F
    Loop {
        Random, r, 1, 658
        Random, t, 0, 1
        WinActivate ahk_class IrfanView
        WinWaitActive ahk_class IrfanView
        if (t = 1)
            Click WheelDown %r%
        else
            Click WheelUp %r%
    }
    return

!#g:: ; Random wheel with delay (1-1000ms) with Alt + Win + G
    Loop {
        Random, r, 1, 658
        Random, s, 1, 1000
        Random, t, 0, 1
        WinActivate ahk_class IrfanView
        WinWaitActive ahk_class IrfanView
        if (t = 1)
            Click WheelDown %r%
        else
            Click WheelUp %r%
        Sleep %s%
    }
    return

!#h:: ; Random wheel with delay (1-6000ms) with Alt + Win + H
    Loop {
        Random, r, 1, 658
        Random, s, 1, 6000
        Random, t, 0, 1
        WinActivate ahk_class IrfanView
        WinWaitActive ahk_class IrfanView
        if (t = 1)
            Click WheelDown %r%
        else
            Click WheelUp %r%
        Sleep %s%
    }
    return

!#j:: ; Random wheel (up to 3000) with delay (1-6000ms) with Alt + Win + J
    Loop {
        Random, r, 1, 3000
        Random, s, 1, 6000
        Random, t, 0, 1
        WinActivate ahk_class IrfanView
        WinWaitActive ahk_class IrfanView
        if (t = 1)
            Click WheelDown %r%
        else
            Click WheelUp %r%
        Sleep %s%
    }
    return

appskey & ':: ; Run or restart HomeSafe View with AppsKey + '
    Process, Exist, HomeSafe View.exe
    if ErrorLevel {
        Process, Close, HomeSafe View.exe
        Sleep 100
        Run "C:\Program Files (x86)\swann\HomeSafe View\HomeSafe View.exe"
    } else {
        Run "C:\Program Files (x86)\swann\HomeSafe View\HomeSafe View.exe"
    }
    return

appskey & \:: ; Run ChatSounds script with AppsKey + \
    Run "C:\cygwin64\bin\mintty.exe" -i /Cygwin-Terminal.ico -h always -e /usr/bin/bash -l /cygdrive/d/bat/chatsoundsopilNuk.sh
    return

appskey & =:: ; Download ChatSounds with AppsKey + =
    Run "C:\cygwin64\bin\mintty.exe" -i /Cygwin-Terminal.ico -e /usr/bin/bash -l /cygdrive/d/bat/game/chatsoundscyg.sh,, Hide
    SoundBeep
    return

!#v:: ; Open random Max 8 patcher with Alt + Win + V
    RunRandom("maxmsp.txt")
    return

!#,:: ; Open random Renoise project with Alt + Win + ,
    RunRandom("renoise.txt")
    return

!#u:: ; Open random Max gen file with Alt + Win + U
    RunRandom("maxgen.txt")
    return

!#b:: ; Open random Max 8 help patcher with Alt + Win + B
    RunRandom("maxhelp.txt")
    return

!#i:: ; Open random Max 8 example patcher with Alt + Win + I
    RunRandom("maxexample.txt")
    return

!#f7:: ; Send random Bible verse with Alt + Win + F7
    RunRandom("bible4.txt", "Send")
    return

!#3:: ; Send random BIP 39 word with Alt + Win + 3
    RunRandom("english.txt", "Send")
    return

#b:: ; Open random ebook with Win + B
    RunRandom("pdf.txt")
    return

!Capslock:: ; Open random URL in Brave and log with Alt + Capslock
    RunRandom("rand.txt", "Run", "", """C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe""")
    SetTitleMatchMode 2
    Sleep 2000
    braveUrl := GetURL("Brave")
    if (braveUrl)
        FileAppend, `n%A_YYYY%-%A_MM%-%A_DD% %A_Hour%:%A_Min%:%A_Sec%`n%braveUrl%`n, his.txt
    SetTitleMatchMode 1
    return

!+z:: ; Search random album on Amazon Music with Alt + Shift + Z
    FileRead, content, albums2.txt
    Sort, content, Random
    line := Trim(SubStr(content, 1, InStr(content, "`r") - 1))
    Run "C:\Program Files\Mozilla Firefox\firefox.exe" "https://music.amazon.ca/search/%line%"
    return

!+x:: ; Open random Dave video with Alt + Shift + X
    RunRandom("dave.txt", "Run", "", """C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe""")
    return

!+c:: ; Open random Vancity video with Alt + Shift + C
    RunRandom("van.txt", "Run", "", """C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe""")
    return

!+v:: ; Open random Ben video with Alt + Shift + V
    RunRandom("ben.txt", "Run", "", """C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe""")
    return

!+b:: ; Open random C++ video with Alt + Shift + B
    RunRandom("randc++.txt", "Run", "", """C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe""")
    return

^!c:: ; Open random chess article and log with Ctrl + Alt + C
    RunRandom("chess2.txt", "Run", "", """C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe""")
    SetTitleMatchMode 2
    Sleep 2000
    braveUrl := GetURL("Brave")
    if (braveUrl)
        FileAppend, `n%A_YYYY%-%A_MM%-%A_DD% %A_Hour%:%A_Min%:%A_Sec%`n%braveUrl%`n, his.txt
    SetTitleMatchMode 1
    return

!3:: ; Open random Terry 2017 video with Alt + 3
    RunRandom("terry2017.txt")
    SetWorkingDir D:\Terry A. Davis - TempleOS Archive\videos\2017
    SetWorkingDir %A_ScriptDir%
    return

!4:: ; Open random Terry 2017b video with Alt + 4
    RunRandom("terry2017b.txt")
    SetWorkingDir D:\Terry A. Davis - TempleOS Archive\videos\2017
    SetWorkingDir %A_ScriptDir%
    return

!5:: ; Open random Terry 2018 video with Alt + 5
    RunRandom("terry2018.txt")
    SetWorkingDir D:\Terry A. Davis - TempleOS Archive\videos\2018
    SetWorkingDir %A_ScriptDir%
    return

!7:: ; Copy random endgame FEN to clipboard with Alt + 7
    FileRead, content, endgame.txt
    Sort, content, Random
    line := Trim(SubStr(content, 1, InStr(content, "`r") - 1))
    Clipboard := line
    return

#c:: ; Run yt-dlp with Win + C
    SendCmd("/cygdrive/d/vid ahk_class VirtualConsoleClass", "y")
    return

#0:: ; Run yt-dlp with subtitles with Win + 0
    SendCmd("/cygdrive/d/vid ahk_class VirtualConsoleClass", "ys")
    return

#z:: ; Run yt-dlp and open in mpv with Win + Z
    SendCmd("/cygdrive/d/vid ahk_class VirtualConsoleClass", "yz")
    return

!#c:: ; Run yt-dlp with -f 18 with Alt + Win + C
    SendCmd("/cygdrive/d/vid ahk_class VirtualConsoleClass", "yt")
    return

#/:: ; Download Newgrounds audio with Win + /
    SendCmd("/cygdrive/d/ng ahk_class VirtualConsoleClass", "yn")
    return

^+c:: ; Run wget with Shift + Ctrl + C
    SendCmd("/cygdrive/d/apps ahk_class VirtualConsoleClass", "wg")
    return

#v:: ; Paste clipboard in quotes in ConEmu with Win + V
    SendCmd("/cygdrive/d/vid ahk_class VirtualConsoleClass", "v", 1)
    return

^f1:: ; Ping and open Starlink stats with Ctrl + F1
    SendCmd("ahk_class VirtualConsoleClass", "g")
    Run http://dishy.starlink.com/statistics
    return

!f9:: ; Play random sound in Sven Co-op with Alt + F9
    RunRandom("spk.txt", "Send", " as_command .s_player_exec @all spk ")
    return

^+!0:: ; Say random Bible verse in Sven Co-op with Shift + Ctrl + Alt + 0
    RunRandom("bible4.txt", "Send", " as_command .s_admin_say 0 1 """" """" 8 @all 255 0 255 -1 -1")
    Send {Enter}
    return

^+!9:: ; Play random scientist line in Sven Co-op with Shift + Ctrl + Alt + 9
    RunRandom("sci.txt", "Send", " .s_player_exec @all ""spk """"")
    Send {Enter}
    return

^!v:: ; Resize and move video players to secondary monitor with Ctrl + Alt + V
    WinMove ahk_exe mpv.exe,, -1083, 88, 1083, 640
    WinMove ahk_exe vlc.exe,, -1083, 88, 1083, 640
    WinMove "Picture in picture",, -1083, 88, 1083, 640
    return

!9:: ; Resize and move Agent DVR to secondary monitor with Alt + 9
    SetTitleMatchMode 2
    WinMove "Agent: Agent DVR - Chromium",, -1083, 478, 1080, 1001
    SetTitleMatchMode 1
    return

f5:: ; Resize and move various windows to secondary monitor with F5
    WinMove ahk_exe mpv.exe,, -1083, -4, 1083, 640
    WinMove ahk_exe vlc.exe,, -1083, -4, 1083, 640
    WinMove "Picture in picture",, -1083, -4, 1083, 640
    return

; Supporting Functions
GetActiveExplorerPath() {
    explorerHwnd := WinActive("ahk_class CabinetWClass")
    if (explorerHwnd) {
        for window in ComObjCreate("Shell.Application").Windows
            if (window.hwnd = explorerHwnd)
                return window.Document.Folder.Self.Path
    }
}

Hotkeys(ByRef Hotkeys) {
    FileRead, Script, %A_ScriptFullPath%
    Script := RegExReplace(Script, "ms`a)^\s*/\*.*?^\s*\*/\s*|^\s*\(.*?^\s*\)\s*")
    Hotkeys := {}
    Loop, Parse, Script, `n, `r
        if RegExMatch(A_LoopField, "^\s*(.*):`:.*`;\s*(.*)", Match)
            Hotkeys.Push({"Hotkey": Match1, "Comment": Match2})
    return Hotkeys
}

GetURL(wTitle*) {
    if !(wId := WinExist(wTitle*))
        return
    IUIAutomation := ComObjCreate("{ff48dba4-60ef-4201-aa87-54103eef594e}", "{30cbe57d-d9d0-452a-ab13-7ac5ac4825ee}")
    DllCall(NumGet(NumGet(IUIAutomation+0)+6*A_PtrSize), "ptr", IUIAutomation, "ptr", wId, "ptr*", elementMain)
    NumPut(addressbarStrPtr := DllCall("oleaut32\SysAllocString", "wstr", "Address and search bar", "ptr"), (VarSetCapacity(addressbar, 8+2*A_PtrSize)+NumPut(8, addressbar, 0, "short"))*0+&addressbar, 8, "ptr")
    DllCall("oleaut32\SysFreeString", "ptr", addressbarStrPtr)
    DllCall(NumGet(NumGet(IUIAutomation+0)+23*A_PtrSize), "ptr", IUIAutomation, "int", 30005, "ptr", &addressbar, "ptr*", addressbarCondition)
    DllCall(NumGet(NumGet(elementMain+0)+5*A_PtrSize), "ptr", elementMain, "int", 0x4, "ptr", addressbarCondition, "ptr*", currentURLElement)
    DllCall(NumGet(NumGet(currentURLElement+0)+10*A_PtrSize), "ptr", currentURLElement, "uint", 30045, "ptr", (VarSetCapacity(currentURL, 8+2*A_PtrSize)+NumPut(0, currentURL, 0, "short")+NumPut(0, currentURL, 8, "ptr"))*0+¤tURL)
    ObjRelease(currentURLElement)
    ObjRelease(elementMain)
    ObjRelease(IUIAutomation)
    return StrGet(NumGet(currentURL, 8, "ptr"), "utf-16")
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Auto