Skip to content

Instantly share code, notes, and snippets.

@TheJoeSchr
Last active January 14, 2018 13:54
Show Gist options
  • Save TheJoeSchr/ca6f0045d05f84ea5793 to your computer and use it in GitHub Desktop.
Save TheJoeSchr/ca6f0045d05f84ea5793 to your computer and use it in GitHub Desktop.
Autohotkey Script to change XonarSwitch profiles
; IMPORTANT INFO ABOUT GETTING STARTED: Lines that start with a
; semicolon, such as this one, are comments. They are not executed.
; This script has a special filename and path because it is automatically
; launched when you run the program directly. Also, any text file whose
; name ends in .ahk is associated with the program, which means that it
; can be launched simply by double-clicking it. You can have as many .ahk
; files as you want, located in any folder. You can also run more than
; one .ahk file simultaneously and each will get its own tray icon.
; SAMPLE HOTKEYS: Below are two sample hotkeys. The first is Win+Z and it
; launches a web site in the default browser. The second is Control+Alt+N
; and it launches a new Notepad window (or activates an existing one). To
; try out these hotkeys, run AutoHotkey again, which will load this file.
;; INITS
#InstallKeybdHook
#InstallMouseHook
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;;;; GLOBAL FUNCTIONS
GetSelectedText() {
tmp = %ClipboardAll% ; save clipboard
Clipboard := "" ; clear clipboard
Send, ^c ; simulate Ctrl+C (=selection in clipboard)
ClipWait, 1 ; wait until clipboard contains data
selection = %Clipboard% ; save the content of the clipboard
Clipboard = %tmp% ; restore old content of the clipboard
return (selection = "" ? Clipboard : selection)
}
; Sends text to a console's input stream. WinTitle may specify any window in
; the target process. Since each process may be attached to only one console,
; ConsoleSend fails if the script is already attached to a console.
ConsoleSend(text, WinTitle="", WinText="", ExcludeTitle="", ExcludeText="")
{
WinGet, pid, PID, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
if !pid
return false, ErrorLevel:="window"
; Attach to the console belonging to %WinTitle%'s process.
if !DllCall("AttachConsole", "uint", pid)
return false, ErrorLevel:="AttachConsole"
hConIn := DllCall("CreateFile", "str", "CONIN$", "uint", 0xC0000000
, "uint", 0x3, "uint", 0, "uint", 0x3, "uint", 0, "uint", 0)
if hConIn = -1
return false, ErrorLevel:="CreateFile"
VarSetCapacity(ir, 24, 0) ; ir := new INPUT_RECORD
NumPut(1, ir, 0, "UShort") ; ir.EventType := KEY_EVENT
NumPut(1, ir, 8, "UShort") ; ir.KeyEvent.wRepeatCount := 1
; wVirtualKeyCode, wVirtualScanCode and dwControlKeyState are not needed,
; so are left at the default value of zero.
Loop, Parse, text ; for each character in text
{
NumPut(Asc(A_LoopField), ir, 14, "UShort")
NumPut(true, ir, 4, "Int") ; ir.KeyEvent.bKeyDown := true
gosub ConsoleSendWrite
NumPut(false, ir, 4, "Int") ; ir.KeyEvent.bKeyDown := false
gosub ConsoleSendWrite
}
gosub ConsoleSendCleanup
return true
ConsoleSendWrite:
if ! DllCall("WriteConsoleInput", "uint", hconin, "uint", &ir, "uint", 1, "uint*", 0)
{
gosub ConsoleSendCleanup
return false, ErrorLevel:="WriteConsoleInput"
}
return
ConsoleSendCleanup:
if (hConIn!="" && hConIn!=-1)
DllCall("CloseHandle", "uint", hConIn)
; Detach from %WinTitle%'s console.
DllCall("FreeConsole")
return
}
ScanCode( wParam, lParam ) {
Clipboard := "SC" SubStr((((lParam>>16) & 0xFF)+0xF000),-2)
GuiControl,, SC, %Clipboard%
}
;;;; HOTKEYS
; opens scancode windows
; ^!h::
; SetFormat, Integer, Hex
; Gui +ToolWindow -SysMenu +AlwaysOnTop
; Gui, Font, s14 Bold, Arial
; Gui, Add, Text, w100 h33 vSC 0x201 +Border, {SC000}
; Gui, Show,, % "// ScanCode //////////"
; Loop 9
; OnMessage( 255+A_Index, "ScanCode" ) ; 0x100 to 0x108
; Return
;disable win+space for language switch
;#Space::
;return
; for teamspack ctrl+shift+t
;XButton1::
;MsgBox This is ok
;Send ^+t
;return
; start remote process debugin in VS for GAE
; Ctrl+Alt+F5
^!F5::
#IfWinActive ahk_class HwndWrapper
;,start debug not needed anymore
;SendInput ^{F5} ;Ctrl+F5
;Sleep 3000 ; Because Server is starting
;Send !{ESC} ;Alt+ESC ;Return to VS, is like Alt+Tab
;msgbox Tab
;Sleep 500
SendInput !d ;Attach to Process Menu
Sleep 300
SendInput !p
Sleep 100
SendInput ppp
; Choose Remote Debug Item in DropDown
;Sleep 5000
Sleep 100
SendInput {Tab}tcp://columbia@localhost:5678{Enter} ;Copy Adress and start
Sleep 200
SendInput {Enter}
Sleep 100
SendInput {Alt Up}{Ctrl Up}
;!a ;Alt+a (attach process)
;Sleep 500
;url="http://localhost:8080"
; don't need it for now
;run % "chrome.exe" ( winExist("ahk_class Chrome_WidgetWin_1") ? " --new-window " : " " ) url
return
;CONTROL+ALT+Left Click to close a window (like xkill)
!^LButton::
MouseGetPos,,, WhichWin,,1
WinGetClass, this_class, ahk_id %WhichWin%
; avoid killing Shell_TrayWnd or Progman windows
if this_class in Shell_TrayWnd,Progman
msgbox invalid window
else
{
WinGet, FoundProcess, PID, ahk_id %WhichWin%
WinClose, ahk_id %WhichWin%
WinWaitClose, ahk_id %WhichWin%,,2
if errorlevel
process, close, %FoundProcess%
}
Return
;; Open Snipping Tool, create a new snip
PrintScreen::
RunWait, SnippingTool.exe ;%A_WinDir%\system32\SnippingTool.exe
SendInput !{n}
return
;; run marked text in google
#g:: Run % "http://www.google.com/search?q=" . GetSelectedText()
;; paste & go in chrome
#IfWinActive ahk_class Chrome_WidgetWin_1
^+v::
^g::
Send, ^l
Send, ^v{Enter} ; simulate Ctrl+C (=selection in clipboard)
#IfWinActive
;; Make Ctrl+W work everywhere (closing windows)
;^w::WinClose, A
;return
;; middle mouse button - up a folder in explorer
#IfWinActive, ahk_class CabinetWClass
~MButton::Send !{Up}
#IfWinActive
; Close all Explorer Windows except the most active window
^#E::
; List gets all ids starting from the topmost down
WinGet, OutList, List, ahk_class CabinetWClass
Loop, %OutList% {
if A_Index = 1
{ ; skip
Continue
}
WinClose, % "ahk_id " OutList%A_Index%
}
return
;Replace selected text with uppercase
; Ctrl+Alt+U
; ^!u::
; Clipboard = ; Empty the clipboard so that ClipWait has something to detect
; SendInput, ^{Ins} ;copies selected text
; ClipWait
; StringReplace, OutputText, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks
; StringUpper, OutputText, OutputText
; SendRaw % OutputText
; VarSetCapacity(OutputText, 0) ;free memory
; Return
;Toggle XonarAudio to switch between headphone and surround
;Ctrl+Alt+ScrollLock
^!ScrollLock::
dxtoggle := !dxtoggle
if dxtoggle
run, xonarswitch.exe /noUI /Profile=Upmix+DB, c:\program files\xonarswitch
else
run, xonarswitch.exe /noUI /Profile=Headphones+DB, c:\program files\xonarswitch
return
;Opens audio configure menu audio to use headphone jack or speakers
;ctrl+shift+alt+scrolllock
^+!scrolllock::
Run, mmsys.cpl
WinWait,Sound ; Change "Sound" to the name of the window in your local language
; ControlSend,SysListView321,{Down 1} ; This number selects the matching audio device in the list, change it accordingly
; ControlClick,&Configure,Sound,,,,na ; Change "&Set Default" to the name of the button in your local language
;Send {ALT DOWN}{C}{ALT UP}
return
; Toggle Audio Output
;Ctrl+Alt+ScrollLock
; ^!ScrollLock::
; toggle:=!toggle ;toggles up and down states.
; Run, mmsys.cpl
; WinWait,Sound ; Change "Sound" to the name of the window in your local language
; if toggle
; ControlSend,SysListView321,{Down 2} ; This number selects the matching audio device in the list, change it accordingly
; Else
; ControlSend,SysListView321,{Up 2} ; This number selects the matching audio device in the list, change it accordingly
; sleep 100
; ControlClick,&Set Default,Sound,,,,na ; Change "&Set Default" to the name of the button in your local language
; sleep 100
; ControlClick,OK,Sound,,,,na
; return
; CTRL+ATL+WIN+ScrollLock: Opens ScoundCard Manager
!^#ScrollLock::
Run, mmsys.cpl
return
; paste in console, cmd, terminal
; ; AutoHotkey Version: 1.x ; Language: English ; Author: Lowell Heddings | geek@howtogeek.com ;
; Script Function: enable paste in the Windows command prompt ;
#IfWinActive ahk_class ConsoleWindowClass
^V::
;SendInput, {RAW}%clipboard%
SendInput {ALT DOWN}{SPACE}{ALT UP}ep
;ConsoleSend(clipboard)
return
#IfWinActive
; Capslock send > windows to other monitor (needs resizer)
; Use Capslock as Ctrl
;Capslock:: Send {Ctrl}
;+Capslock::Capslock
; SENDS awwcuteapp url to Inupt
; CTRL+ALT+SHIFT+INSTERT
^!+Insert::
SendInput http://j.mp/1KabQC1^{Enter}
return
; opens CMD in current explorer folder
#IfWinActive ahk_class CabinetWClass ; for use in explorer.
^!r::
;ClipSaved := ClipboardAll
;SendInput, !d
;Sleep 100
;SendInput, ^{Ins}
;Sleep 100
;Run, cmd /K "cd /D `"%clipboard%`""
;Clipboard := ClipSaved
;ClipSaved =
SendInput {ALT DOWN}fma{ALT UP}
return
#IfWinActive
; opens GIT bash in current explorer folder
#IfWinActive ahk_class CabinetWClass ; for use in explorer.
^!b::
ClipSaved := ClipboardAll
SendInput, !d
Sleep 100
SendInput, ^{Ins}
Sleep 100
Run, cmd /K "cd /D `"%clipboard%`"&`"C:\Program Files (x86)\Git\bin\sh.exe`" --login"
Sleep 100
Clipboard := ClipSaved
ClipSaved =
return
#IfWinActive
; opens POWERSHELL in current explorer folder
#IfWinActive ahk_class CabinetWClass ; for use in explorer.
^!s::
ClipSaved := ClipboardAll
SendInput, !d
Sleep 100
SendInput, ^{Ins}
Sleep 100
Run, powershell -NoExit -Command Set-Location -LiteralPath '"`"%clipboard%`""'
Clipboard := ClipSaved
ClipSaved =
return
#IfWinActive
;ctrl+alt+n opens new notepad
^!n::
IfWinExist emacs@JOES-CRUNCHBOX
WinActivate
else
Run Notepad
return
; Remove Window Border and send to 2nd monitor
;ctrl+shift+ALT+WIN+F11
#^+!F11::
WinGet, TempWindowID, ID, A
If (WindowID != TempWindowID)
{
WindowID:=TempWindowID
WindowState:=0
}
If (WindowState != 1)
{
WinGetPos, WinPosX, WinPosY, WindowWidth, WindowHeight, ahk_id %WindowID%
WinSet, Style, ^0xC40000, ahk_id %WindowID%
Modifier := 7
NewPosX := 1920 - Modifier
NewPosY := Modifier * (-1)
NewWidth := 1680 + (Modifier*2)
NewHeight := 1050 + (Modifier*2)
WinMove, ahk_id %WindowID%, , NewPosX, NewPosY, NewWidth, NewHeight
}
Else
{
WinSet, Style, ^0xC40000, ahk_id %WindowID%
WinMove, ahk_id %WindowID%, , WinPosX, WinPosY, WindowWidth, WindowHeight
}
WindowState:=!WindowState
return
; Just Remove Window Border
;ctrl+shift+F11
#^+F11::
WinGet, TempWindowID, ID, A
If (WindowID != TempWindowID)
{
WindowID:=TempWindowID
WindowState:=0
}
If (WindowState != 1)
{
WinSet, Style, ^0xC40000, ahk_id %WindowID%
}
Else
{
WinSet, Style, ^0xC40000, ahk_id %WindowID%
}
WindowState:=!WindowState
return
;withouth border and stretch
; win+F11
#F11:: WinGet, TempWindowID, ID, A
If (WindowID != TempWindowID)
{
WindowID:=TempWindowID
WindowState:=0
}
If (WindowState != 1)
{
WinGetPos, WinPosX, WinPosY, WindowWidth, WindowHeight, ahk_id %WindowID%
WinSet, Style, ^0xC40000, ahk_id %WindowID%
; WinMove, ahk_id %WindowID%, , -7, -7, 1934, 1214
;windowborder
Modifier := 3
;Modifier := WindowBorder
NewPos := Modifier * (-1)
NewWidth := A_ScreenWidth + (Modifier*2)
NewHeight := A_ScreenHeight + (Modifier*2)
WinMove, ahk_id %WindowID%, , NewPos, NewPos, NewWidth, NewHeight
}
Else
{
WinSet, Style, ^0xC40000, ahk_id %WindowID%
WinMove, ahk_id %WindowID%, , WinPosX, WinPosY, WindowWidth, WindowHeight
}
WindowState:=!WindowState
return
;; TransparentWindow
; I call this script "TransparentWindow". If you press Ctrl+Shift+ALT+T (which I have bound
; to an extra button on my mouse), it will bring up a small dialog which has a slider
; which controls the opacity of the window currently underneath the mouse, and a
; checkbox which enables "Always on top" for the current window.
;Init
{
#Persistent
#SingleInstance force
CoordMode, Mouse, Screen
SetTitleMatchMode, 2
SetupTrayMenu()
GUI_HIDE_TIME = 3000
FADE_STEP_AMT = 10
Return
}
SetupTrayMenu()
{
Menu, Tray, NoStandard
Menu, Tray, Add, Remove transparency from all windows, ShowAll
Menu, Tray, Add
Menu, Tray, Standard
Return
}
ShowAll:
{
WinGet, id, list
Loop, %id%
{
WinSet, Transparent, Off, % "ahk_id" id%A_Index%
}
Return
}
;Shift+Alt+Ctrl+Win+T
^+!#T::
{
GetTransInfo(true)
Return
}
GetTransInfo(bUseWinUnderMouse)
{
global g_iPosX
global g_iPosY
global g_iActiveWinID
global g_bWinOnTop
IfWinExist, TransGui
{
Gui, Destroy
}
Else
{
If( bUseWinUnderMouse )
{
MouseGetPos, g_iPosX, g_iPosY, g_iActiveWinID
}
WinGet, hWinExStyle, ExStyle, ahk_id %g_iActiveWinID%
; 0x8 is WS_EX_TOPMOST.
g_bWinOnTop := (hWinExStyle & 0x8) > 0
CreateGui()
}
Return
}
CreateGui()
{
global g_iTransAmt
global g_iTransText
global g_iActiveWinID
global g_bWinOnTop
global g_iPosX
global g_iPosY
global GUI_HIDE_TIME
Gui, Destroy
WinGet, g_iTransAmt, Transparent, ahk_id %g_iActiveWinID%
If(g_iTransAmt == "")
{
g_iTransAmt = 255
}
g_iTransAmt := Round( g_iTransAmt / 2.55 )
Gui, +ToolWindow -Caption +Border +AlwaysOnTop
Gui, Add, Text, w25 vg_iTransText, %g_iTransAmt%`%
Gui, Add, Slider, Vertical Invert NoTicks AltSubmit Center Line5 Page100 Buddy1g_iTransText Buddy2g_bWinOnTop gChangeWinTrans vg_iTransAmt, %g_iTransAmt%
Gui, Add, Checkbox, vg_bWinOnTop gChangeWinTop Checked%g_bWinOnTop%, Top
Gui, Margin, 0
GetGuiPos()
Gui, Show, x%g_iPosX% y%g_iPosY%, TransGui
SetTimer, CheckToHide, %GUI_HIDE_TIME%
Return
}
GetGuiPos()
{
global g_iPosY
global g_iPosX
global g_iTransAmt
SysGet, iVirtualScreenHeight, 79
SysGet, iVirtualScreenWidth, 78
If( g_iPosX < 22 )
{
g_iPosX = 0
}
Else If( g_iPosX > iVirtualScreenWidth - 29 )
{
g_iPosX := iVirtualScreenWidth - 51
}
Else
{
g_iPosX -= 22
}
If( g_iPosY < 40 )
{
g_iPosY = 0
}
Else If( g_iPosY > iVirtualScreenHeight - 77 )
{
g_iPosY := iVirtualScreenHeight - 115
}
Else
{
g_iPosY -= (78 - (Round(g_iTransAmt/2.63)))
}
Return
}
CheckToHide:
{
MouseGetPos,,,iCurWinId
WinGet, iTransGuiID,,TransGui
If( iCurWinId == iTransGuiID )
{
SetTimer, CheckToHide, %GUI_HIDE_TIME%
}
Else
{
HideGui()
}
Return
}
HideGui()
{
global g_iHideFadeAmt
g_iHideFadeAmt = 255
SetTimer, MiniLoop, 1
SetTimer, CheckToHide, Off
Return
}
MiniLoop:
{
If( g_iHideFadeAmt <= 0)
{
Gui, Destroy
SetTimer, MiniLoop, Off
}
Else
{
WinSet, Transparent, %g_iHideFadeAmt%, TransGui
g_iHideFadeAmt -= %FADE_STEP_AMT%
}
Return
}
ChangeWinTop:
{
SetTimer, CheckToHide, %GUI_HIDE_TIME%
SetTimer, MiniLoop, Off
WinSet, Transparent, 255, TransGui
GuiControlGet, g_bWinOnTop
If( g_bWinOnTop )
{
WinSet, AlwaysOnTop, On, ahk_id %g_iActiveWinID%
WinSet, AlwaysOnTop, On, TransGui
}
Else
{
WinSet, AlwaysOnTop, Off, ahk_id %g_iActiveWinID%
}
Return
}
ChangeWinTrans:
{
Sleep 100
GuiControlGet, g_iTransAmt
SetTimer, CheckToHide, %GUI_HIDE_TIME%
SetTimer, MiniLoop, Off
WinSet, Transparent, 255, TransGui
If(g_iTransAmt == 100)
{
WinSet, Transparent, Off, ahk_id %g_iActiveWinID%
}
Else
{
iRealTransAmt := Round( g_iTransAmt * 2.55 )
WinSet, Transparent, %iRealTransAmt%, ahk_id %g_iActiveWinID%
}
GuiControl,, g_iTransText, %g_iTransAmt%`%
iRealTransAmt =
Return
}
; Note: From now on whenever you run AutoHotkey directly, this script
; will be loaded. So feel free to customize it to suit your needs.
; Please read the QUICK-START TUTORIAL near the top of the help file.
; It explains how to perform common automation tasks such as sending
; keystrokes and mouse clicks. It also explains more about hotkeys.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment