Skip to content

Instantly share code, notes, and snippets.

@abatkin
Last active January 28, 2021 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abatkin/dbddc057b627bea0fd95 to your computer and use it in GitHub Desktop.
Save abatkin/dbddc057b627bea0fd95 to your computer and use it in GitHub Desktop.
Keyboard setup
; VirtuaWin - Switch to next desktop
sc169:: ; Forward
PostMessage, 1034, 1026, 0, , VirtuaWinMainClass
return
; VirtuaWin - Bring window to next desktop
+sc169:: ; Shift+Forward
PostMessage, 1049, 0, -1026, , VirtuaWinMainClass
return
; VirtuaWin - Switch to prev desktop
sc16A:: ; Back
PostMessage, 1034, 1025, 0, , VirtuaWinMainClass
return
; VirtuaWin - Bring window to prev desktop
+sc16A:: ; Shift+Back
PostMessage, 1049, 0, -1025, , VirtuaWinMainClass
return
; Launch and raise PuTTY
sc165::
LaunchAndRaise("C:\apps\putty\PUTTY.EXE -load s1", "ahk_class PuTTY")
return
; Launch and raise Firefox
sc132:: ; BrowserHome
LaunchAndRaise("C:\Program Files (x86)\Mozilla Firefox\firefox.exe", "ahk_class MozillaWindowClass")
return
; Launch and raise calculator
sc121:: ; Calculator
LaunchAndRaise("C:\apps\SpeedCrunch\speedcrunch.exe", "SpeedCrunch ahk_class QWidget")
return
; Win+Space doesn't always work properly so remap
#space::SendInput ^#{Space}
; Launch or raise my personal wiki
^!+W::
LaunchOrFind("C:\apps\Vim\vim74\gvim.exe -c VimwikiIndex", "vimwiki ahk_class Vim")
return
; Run vim
^!+V::
Run, C:\apps\Vim\vim74\gvim.exe, h:\
return
; Launch vim, paste, visuall select pasted selection
^!+P::
Run, C:\apps\Vim\vim74\gvim.exe -c "normal ""+pgp", h:\
return
; Ctrl+Shift+N in PuTTY will duplicate the current session
#IfWinActive ahk_class PuTTY
^+n::PostMessage, 0x112, 0x0030
#IfWinActive
; Ctrl+L, Ctrl+K and Ctrl+PgUp/PgDn work like other browsers
#IfWinActive ahk_class IEFrame
^l::Send {f4}
^k::Send ^e
^PgUp::Send +^{Tab}
^PgDn::Send ^{Tab}
#ifWinActive
; Launch window or raise existing one
LaunchOrFind(executable, searchString) {
DetectHiddenWindows, on
SetTitleMatchMode, 2
WinGet, winId, ID, %searchString%
if (winId) {
PostMessage, 1063, %winId%, 1, , VirtuaWinMainClass
Sleep, 100
WinActivate, ahk_id %winId%
} else {
Run %executable%
}
}
; Launch app and make sure it is raised
LaunchAndRaise(executable, winclass) {
SetTitleMatchMode, 2
WinGet, idListBefore, List, %winclass%
Run %executable%
Sleep, 2000
WinGet, idListAfter, List, %winclass%
idx1 := 1
Loop %idListAfter% {
winIdNew := idListAfter%idx1%
found := 0
idx2 := 1
Loop %idListBefore% {
winIdOld := idListBefore%idx2%
if (winIdNew == winIdOld) {
found := 1
}
idx2 := idx2 + 1
}
if (found == 0) {
WinActivate, ahk_id %winIdNew%
}
idx1 := idx1 + 1
}
}
; Not sure what this does, must be some old cruft
GetRealActiveWindow() {
activeWinId := WinActive("A")
WinGet, Style, Style, ahk_id %activeWinId%
if ((Style & 0x800000) && (Style & 0x400000) && !(Style & 0x40000000) && !(Style & 0x80000000)) {
return %activeWinId%
}
}
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\IntelliType Pro\ModelSpecific\1016\EventMapping\82]
"Command"=dword:0000019c
"Keystroke"=dword:00000757
"KeystrokeText"="Ctrl + Alt + Shift + W"
"Macro"="Escape.mhm"
; Launch and raise Firefox
sc132:: ; BrowserHome
Run, "C:\Program Files\Mozilla Firefox\firefox.exe"
return
; Launch and raise PuTTY
sc165::
Run, C:\apps\PuTTY.exe -load s1, , , OutputVarPID
WinWait ahk_pid %OutputVarPID%
WinActivate
return
; Launch cmd
sc16c::
Run, c:\windows\system32\cmd.exe /k "cd C:\"
return
; Ctrl+Shift+N in PuTTY will duplicate the current session
#IfWinActive ahk_class PuTTY
^+n::PostMessage, 0x112, 0x0030
#IfWinActive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment