Autohotkey file aiming to resemble i3wm behaviour on my main machine
This commit is contained in:
parent
476513cbc8
commit
4b9fdad861
197
arch-config/i3-like.ahk
Normal file
197
arch-config/i3-like.ahk
Normal file
@ -0,0 +1,197 @@
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
; Environment variables
|
||||
CoordMode, Mouse, Screen
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
; unset keys
|
||||
Alt & F4::return
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
; set custom keys
|
||||
LWin & q::PostMessage, 0x112, 0xF060,,, A ;closes active window, 0x112 = WM_SYSCOMMAND, 0xF060 = SC_CLOSE
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
; Programs
|
||||
^!f::Run Firefox
|
||||
^!e::Run C:\Prog\emacs\x86_64\bin\runemacs.exe
|
||||
^!b::Run Outlook
|
||||
^!t::Run Explorer
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
; Unfinished
|
||||
^!a::Click, 10, 1070 ; HACK find a better solution to this
|
||||
LWin::return
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
; Stuff copied from the internet
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
; Switching Virtual Desktops with super+number
|
||||
; Globals
|
||||
DesktopCount = 10 ; Windows starts with 10 desktops at boot
|
||||
CurrentDesktop = 1 ; Desktop count is 1-indexed (Microsoft numbers them this way)
|
||||
;
|
||||
; This function examines the registry to build an accurate list of the current virtual desktops and which one we're currently on.
|
||||
; Current desktop UUID appears to be in HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\SessionInfo\1\VirtualDesktops
|
||||
; List of desktops appears to be in HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VirtualDesktops
|
||||
;
|
||||
mapDesktopsFromRegistry() {
|
||||
global CurrentDesktop, DesktopCount
|
||||
; Get the current desktop UUID. Length should be 32 always, but there's no guarantee this couldn't change in a later Windows release so we check.
|
||||
IdLength := 32
|
||||
SessionId := getSessionId()
|
||||
if (SessionId) {
|
||||
RegRead, CurrentDesktopId, HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\SessionInfo\%SessionId%\VirtualDesktops, CurrentVirtualDesktop
|
||||
if (CurrentDesktopId) {
|
||||
IdLength := StrLen(CurrentDesktopId)
|
||||
}
|
||||
}
|
||||
; Get a list of the UUIDs for all virtual desktops on the system
|
||||
RegRead, DesktopList, HKEY_CURRENT_USER, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VirtualDesktops, VirtualDesktopIDs
|
||||
if (DesktopList) {
|
||||
DesktopListLength := StrLen(DesktopList)
|
||||
; Figure out how many virtual desktops there are
|
||||
DesktopCount := DesktopListLength / IdLength
|
||||
}
|
||||
else {
|
||||
DesktopCount := 1
|
||||
}
|
||||
; Parse the REG_DATA string that stores the array of UUID's for virtual desktops in the registry.
|
||||
i := 0
|
||||
while (CurrentDesktopId and i < DesktopCount) {
|
||||
StartPos := (i * IdLength) + 1
|
||||
DesktopIter := SubStr(DesktopList, StartPos, IdLength)
|
||||
OutputDebug, The iterator is pointing at %DesktopIter% and count is %i%.
|
||||
; Break out if we find a match in the list. If we didn't find anything, keep the
|
||||
; old guess and pray we're still correct :-D.
|
||||
if (DesktopIter = CurrentDesktopId) {
|
||||
CurrentDesktop := i + 1
|
||||
OutputDebug, Current desktop number is %CurrentDesktop% with an ID of %DesktopIter%.
|
||||
break
|
||||
}
|
||||
i++
|
||||
}
|
||||
}
|
||||
;
|
||||
; This functions finds out ID of current session.
|
||||
;
|
||||
getSessionId()
|
||||
{
|
||||
ProcessId := DllCall("GetCurrentProcessId", "UInt")
|
||||
if ErrorLevel {
|
||||
OutputDebug, Error getting current process id: %ErrorLevel%
|
||||
return
|
||||
}
|
||||
OutputDebug, Current Process Id: %ProcessId%
|
||||
DllCall("ProcessIdToSessionId", "UInt", ProcessId, "UInt*", SessionId)
|
||||
if ErrorLevel {
|
||||
OutputDebug, Error getting session id: %ErrorLevel%
|
||||
return
|
||||
}
|
||||
OutputDebug, Current Session Id: %SessionId%
|
||||
return SessionId
|
||||
}
|
||||
;
|
||||
; This function switches to the desktop number provided.
|
||||
;
|
||||
switchDesktopByNumber(targetDesktop)
|
||||
{
|
||||
global CurrentDesktop, DesktopCount
|
||||
; Re-generate the list of desktops and where we fit in that. We do this because
|
||||
; the user may have switched desktops via some other means than the script.
|
||||
mapDesktopsFromRegistry()
|
||||
; Don't attempt to switch to an invalid desktop
|
||||
if (targetDesktop > DesktopCount || targetDesktop < 1) {
|
||||
OutputDebug, [invalid] target: %targetDesktop% current: %CurrentDesktop%
|
||||
return
|
||||
}
|
||||
; Go right until we reach the desktop we want
|
||||
while(CurrentDesktop < targetDesktop) {
|
||||
Send ^#{Right}
|
||||
CurrentDesktop++
|
||||
OutputDebug, [right] target: %targetDesktop% current: %CurrentDesktop%
|
||||
}
|
||||
; Go left until we reach the desktop we want
|
||||
while(CurrentDesktop > targetDesktop) {
|
||||
Send ^#{Left}
|
||||
CurrentDesktop--
|
||||
OutputDebug, [left] target: %targetDesktop% current: %CurrentDesktop%
|
||||
}
|
||||
}
|
||||
;
|
||||
; This function creates a new virtual desktop and switches to it
|
||||
;
|
||||
createVirtualDesktop()
|
||||
{
|
||||
global CurrentDesktop, DesktopCount
|
||||
Send, #^d
|
||||
DesktopCount++
|
||||
CurrentDesktop = %DesktopCount%
|
||||
OutputDebug, [create] desktops: %DesktopCount% current: %CurrentDesktop%
|
||||
}
|
||||
;
|
||||
; This function deletes the current virtual desktop
|
||||
;
|
||||
deleteVirtualDesktop()
|
||||
{
|
||||
global CurrentDesktop, DesktopCount
|
||||
Send, #^{F4}
|
||||
DesktopCount--
|
||||
CurrentDesktop--
|
||||
OutputDebug, [delete] desktops: %DesktopCount% current: %CurrentDesktop%
|
||||
}
|
||||
; Main
|
||||
SetKeyDelay, 75
|
||||
mapDesktopsFromRegistry()
|
||||
OutputDebug, [loading] desktops: %DesktopCount% current: %CurrentDesktop%
|
||||
; User config!
|
||||
; This section binds the key combo to the switch/create/delete actions
|
||||
LWin & 1::switchDesktopByNumber(1)
|
||||
LWin & 2::switchDesktopByNumber(2)
|
||||
LWin & 3::switchDesktopByNumber(3)
|
||||
LWin & 4::switchDesktopByNumber(4)
|
||||
LWin & 5::switchDesktopByNumber(5)
|
||||
LWin & 6::switchDesktopByNumber(6)
|
||||
LWin & 7::switchDesktopByNumber(7)
|
||||
LWin & 8::switchDesktopByNumber(8)
|
||||
LWin & 9::switchDesktopByNumber(9)
|
||||
LWin & 0::switchDesktopByNumber(10)
|
||||
;LWin & Tab::switchDesktopByNumber(CurrentDesktop + 1)
|
||||
;<#+Tab::switchDesktopByNumber(CurrentDesktop - 1)
|
||||
;CapsLock & c::createVirtualDesktop()
|
||||
;CapsLock & d::deleteVirtualDesktop()
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
Loading…
Reference in New Issue
Block a user