dotfiles/win/win.ahk

190 lines
4.1 KiB
AutoHotkey
Raw Normal View History

2021-01-29 15:32:21 +00:00
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
CoordMode, Mouse, Screen ; mouse coordinates relative to the screen
; =========================
; CONFIGURATION
; =========================
global RATIO := 0.618
; =========================
; BINDINGS
; =========================
2020-05-10 07:20:40 +00:00
^Esc:: Send ^{``}
*#q:: !F4
#Esc:: Reload
2020-05-10 07:20:40 +00:00
^BS::
Send ^a
Send {BS}
return
#=::SoundSet,+5
#-::SoundSet,-5
#BS::#l
2021-01-29 15:32:21 +00:00
#f:: ToggleActiveWinMaximum()
^#p::ShowActiveWinGeometry()
#j:: FocusWinByDirection("right")
#k:: FocusWinByDirection("left")
#+j::MoveActiveWinByDirection("right")
#+k::MoveActiveWinByDirection("left")
2020-05-10 07:20:40 +00:00
; Ctrl + Alt + v : paste as plain text
2020-05-10 07:20:40 +00:00
^!v::
Clip0 = %ClipBoardAll%
ClipBoard = %ClipBoard% ; Convert to plain text
Send ^v
Sleep 1000
ClipBoard = %Clip0%
VarSetCapacity(Clip0, 0) ; Free memory
Return
2021-01-29 15:32:21 +00:00
; Ctrl + Alt + Shift + v : paste as plain test a replace \ with /
2020-05-10 07:20:40 +00:00
^+!v::
Clip0 = %ClipBoardAll%
ClipBoard := StrReplace(ClipBoard, "\", "/") ; Convert to plain text
Send ^v
Sleep 1000
ClipBoard = %Clip0%
VarSetCapacity(Clip0, 0) ; Free memory
Return
2021-01-29 15:32:21 +00:00
; move cursor to center of window after switching
~#1 Up::
~#2 Up::
~#3 Up::
~#4 Up::
~#5 Up::
~#6 Up::
~#7 Up::
~#8 Up::
~#9 Up::
Sleep 100
SetCursorToCenterOfActiveWin()
return
~!Tab Up::
while (GetKeyState("Alt") != 0 or GetKeyState("Tab") != 0) {
Sleep 50
}
Sleep 100
WinGetPos, x, y, w, h, A
SetCursorToCenterOfActiveWin()
return
2020-05-10 07:20:40 +00:00
2021-01-29 15:32:21 +00:00
; =========================
; CAPSLOCK AS HYBRID KEY
; =========================
; Capslock & h:: Send {Left}
; Capslock & j:: Send {Down}
; Capslock & k:: Send {Up}
; Capslock & l:: Send {Right}
; Capslock & y:: Send {Browser_Back}
; Capslock & u:: Send ^{PgUp}
; Capslock & i:: Send ^{PgDn}
; Capslock & o:: Send {Browser_Forward}
; Capslock & BackSpace:: Send {Del}
; Capslock & n:: Send {Home}
; Capslock & m:: Send {PgUp}
; Capslock & ,:: Send {PgDn}
; Capslock & .:: Send {End}
; Capslock & Space:: SetCapsLockState % !GetKeyState("CapsLock", "T")
; +CapsLock::
; Send {~}
; SetCapsLockState % !GetKeyState("CapsLock", "T")
; Return
; Capslock::return
2021-01-29 15:32:21 +00:00
; =========================
; FUNCTIONS
; =========================
#Include, WinGetPosEx.ahk
ShowGeometry(x, y, w, h) {
MsgBox, , Geometry,% Format("x:{}, y:{}, w: {}, h: {}", x, y, w, h)
}
ShowActiveWinGeometry() {
WinGetPos x, y, w, h, A
ShowGeometry(x, y, w, h)
}
SetCursorPos(x, y) {
DllCall("SetCursorPos", "int", x, "int", y)
2021-01-29 15:32:21 +00:00
}
FocusWinUnderCursor() {
MouseGetPos, MouseX, MouseY, WinId
WinActivate, ahk_id %WinId%
2021-01-29 15:32:21 +00:00
}
SetCursorToCenterOfActiveWin() {
WinGetPos x, y, w, h, A
2021-01-29 15:32:21 +00:00
SetCursorPos(x + w / 2, y + h / 2)
}
2021-01-29 15:32:21 +00:00
FocusWinByPos(x, y) {
SetCursorPos(x, y)
FocusWinUnderCursor()
SetCursorToCenterOfActiveWin()
}
2021-01-29 15:32:21 +00:00
GetCursorMonGeometry(ByRef x, ByRef y, ByRef w, ByRef h) {
MouseGetPos, MouseX, MouseY
SysGet, mc, MonitorCount
2021-01-29 15:32:21 +00:00
; find current monitor
mi := 0
loop {
2021-01-29 15:32:21 +00:00
SysGet, mon, MonitorWorkArea, %mi%
if (monLeft < MouseX and monRight > MouseX) {
2021-01-29 15:32:21 +00:00
x := monLeft
y := monTop
w := monRight - monLeft
h := monBottom - monTop
return
}
}
}
2021-01-29 15:32:21 +00:00
FocusWinByDirection(direction) {
global RATIO
GetCursorMonGeometry(x, y, w, h)
wf := RATIO / 2
hf := 0.5
if (direction = "right")
wf := RATIO + (1 - RATIO) / 2
FocusWinByPos(x + w * wf, y + h * hf)
}
MoveActiveWinByDirection(direction) {
WinGet, isMax, MinMax, A
if (isMax) {
WinRestore, A
}
2021-01-29 15:32:21 +00:00
global RATIO
GetCursorMonGeometry(x, y, w, h)
activeWinId := WinExist("A")
WinGetPosEx(activeWinId, wx, wy, ww, wh, l, t, r, b)
2021-06-03 16:01:56 +00:00
wx := x
2021-01-29 15:32:21 +00:00
wy := y
ww := floor(w * RATIO)
wh := h
if (direction = "right") {
wx := ww
ww := w - ww
}
WinMove, A,, wx - l, wy - t, ww + l + r, wh + t + b
}
2021-01-29 15:32:21 +00:00
ToggleActiveWinMaximum() {
2021-01-27 12:21:39 +00:00
WinGet, isMax, MinMax, A
if (isMax) {
WinRestore, A
} else {
WinMaximize, A
}
2021-06-03 16:01:56 +00:00
}