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
|
|
|
|
; =========================
|
2021-06-06 09:24:43 +00:00
|
|
|
; global RATIO := 0.618
|
|
|
|
global RATIO := 0.382
|
2021-06-30 06:49:50 +00:00
|
|
|
global ID_SEEN := Object()
|
2021-07-01 14:16:25 +00:00
|
|
|
global ARRANGEMENT := Object()
|
2021-06-30 06:49:50 +00:00
|
|
|
global ARRANGEMENT_PATH := A_AppData . "\arrangement.json"
|
2021-07-01 14:16:25 +00:00
|
|
|
global PADDING := 10
|
2021-06-30 06:49:50 +00:00
|
|
|
LoadArrangement()
|
|
|
|
WatchNewWindow()
|
2021-01-29 15:32:21 +00:00
|
|
|
; =========================
|
|
|
|
; BINDINGS
|
|
|
|
; =========================
|
2020-05-10 07:20:40 +00:00
|
|
|
^Esc:: Send ^{``}
|
2020-07-23 01:52:04 +00:00
|
|
|
*#q:: !F4
|
|
|
|
#Esc:: Reload
|
2020-05-10 07:20:40 +00:00
|
|
|
^BS::
|
|
|
|
Send ^a
|
|
|
|
Send {BS}
|
|
|
|
return
|
2021-07-01 14:16:25 +00:00
|
|
|
#=::SoundSet, +5
|
|
|
|
#-::SoundSet, -5
|
|
|
|
#\::Send {Volume_Mute}
|
2020-07-23 01:52:04 +00:00
|
|
|
#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")
|
2021-06-30 06:49:50 +00:00
|
|
|
#+r::reload
|
2021-07-01 14:16:25 +00:00
|
|
|
#i::IgnoreArrangementForActiveWindow()
|
|
|
|
#+i::UnignoreArrangementForActiveWindow()
|
2021-06-30 06:49:50 +00:00
|
|
|
#t::ShowDebug()
|
2020-05-10 07:20:40 +00:00
|
|
|
|
2020-07-23 01:52:04 +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
|
|
|
|
; =========================
|
2020-07-23 01:52:04 +00:00
|
|
|
|
|
|
|
; 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}
|
|
|
|
|
2021-07-01 14:16:25 +00:00
|
|
|
; Capslock & Space:: SetCapsLockState % !GetKeyState("CapsLock", "T")
|
2020-07-23 01:52:04 +00:00
|
|
|
; +CapsLock::
|
|
|
|
; Send {~}
|
|
|
|
; SetCapsLockState % !GetKeyState("CapsLock", "T")
|
|
|
|
; Return
|
|
|
|
; Capslock::return
|
|
|
|
|
2021-01-29 15:32:21 +00:00
|
|
|
; =========================
|
|
|
|
; FUNCTIONS
|
|
|
|
; =========================
|
|
|
|
|
|
|
|
#Include, WinGetPosEx.ahk
|
2021-06-30 06:49:50 +00:00
|
|
|
#Include, JSON.ahk
|
2021-01-29 15:32:21 +00:00
|
|
|
|
|
|
|
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) {
|
2020-07-23 03:01:09 +00:00
|
|
|
DllCall("SetCursorPos", "int", x, "int", y)
|
2021-01-29 15:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FocusWinUnderCursor() {
|
2020-07-23 03:01:09 +00:00
|
|
|
MouseGetPos, MouseX, MouseY, WinId
|
|
|
|
WinActivate, ahk_id %WinId%
|
2021-01-29 15:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SetCursorToCenterOfActiveWin() {
|
2021-01-21 16:15:44 +00:00
|
|
|
WinGetPos x, y, w, h, A
|
2021-01-29 15:32:21 +00:00
|
|
|
SetCursorPos(x + w / 2, y + h / 2)
|
2020-07-23 03:01:09 +00:00
|
|
|
}
|
|
|
|
|
2021-01-29 15:32:21 +00:00
|
|
|
FocusWinByPos(x, y) {
|
|
|
|
SetCursorPos(x, y)
|
|
|
|
FocusWinUnderCursor()
|
|
|
|
SetCursorToCenterOfActiveWin()
|
2020-07-23 01:52:04 +00:00
|
|
|
}
|
|
|
|
|
2021-01-29 15:32:21 +00:00
|
|
|
GetCursorMonGeometry(ByRef x, ByRef y, ByRef w, ByRef h) {
|
2020-07-23 03:01:09 +00:00
|
|
|
MouseGetPos, MouseX, MouseY
|
|
|
|
SysGet, mc, MonitorCount
|
2021-01-29 15:32:21 +00:00
|
|
|
; find current monitor
|
2020-07-23 03:01:09 +00:00
|
|
|
mi := 0
|
|
|
|
loop {
|
2021-01-29 15:32:21 +00:00
|
|
|
SysGet, mon, MonitorWorkArea, %mi%
|
2020-07-23 03:01:09 +00:00
|
|
|
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
|
2020-07-23 03:01:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
2021-02-27 01:52:47 +00:00
|
|
|
WinGet, isMax, MinMax, A
|
|
|
|
if (isMax) {
|
|
|
|
WinRestore, A
|
|
|
|
}
|
2021-01-29 15:32:21 +00:00
|
|
|
global RATIO
|
2021-07-01 14:16:25 +00:00
|
|
|
global PADDING
|
2021-01-29 15:32:21 +00:00
|
|
|
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") {
|
2021-07-01 14:16:25 +00:00
|
|
|
wx := ww + floor(PADDING / 2)
|
2021-01-29 15:32:21 +00:00
|
|
|
ww := w - ww
|
2021-07-01 14:16:25 +00:00
|
|
|
} else {
|
|
|
|
wx := wx + PADDING
|
2021-01-29 15:32:21 +00:00
|
|
|
}
|
2021-07-01 14:16:25 +00:00
|
|
|
ww := ww - floor(PADDING * 1.5)
|
|
|
|
wy := wy + PADDING
|
|
|
|
wh := wh - PADDING * 2
|
|
|
|
WinMove, A,, wx - l, wy - t, ww + l + r, wh + t + b
|
|
|
|
SaveActiveWindowDirection(direction)
|
2021-01-29 15:32:21 +00:00
|
|
|
}
|
2020-07-23 03:01:09 +00:00
|
|
|
|
2021-06-30 06:49:50 +00:00
|
|
|
|
|
|
|
SaveArrangement() {
|
|
|
|
global ARRANGEMENT
|
|
|
|
global ARRANGEMENT_PATH
|
|
|
|
file := FileOpen(ARRANGEMENT_PATH, "w")
|
|
|
|
file.Write(JSON.Dump(ARRANGEMENT,, 2))
|
|
|
|
file.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
LoadArrangement() {
|
|
|
|
global ARRANGEMENT
|
|
|
|
global ARRANGEMENT_PATH
|
|
|
|
try {
|
|
|
|
FileRead, temp, %ARRANGEMENT_PATH%
|
|
|
|
ARRANGEMENT := JSON.Load(temp)
|
|
|
|
} catch {
|
|
|
|
ARRANGEMENT := Object()
|
|
|
|
}
|
|
|
|
if not IsObject(ARRANGEMENT) {
|
|
|
|
ARRANGEMENT := Object()
|
|
|
|
}
|
2021-07-01 14:16:25 +00:00
|
|
|
if not IsObject(ARRANGEMENT["windows"]) {
|
|
|
|
ARRANGEMENT["windows"] := Object()
|
|
|
|
}
|
|
|
|
if not IsObject(ARRANGEMENT["ignore"]) {
|
|
|
|
ARRANGEMENT["ignore"] := Object()
|
|
|
|
}
|
2021-06-30 06:49:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GetActiveWindowClassPath() {
|
|
|
|
WinGet processPath, ProcessPath, A
|
|
|
|
WinGetClass windowClass, A
|
|
|
|
return processPath . ":" . windowClass
|
|
|
|
}
|
|
|
|
|
|
|
|
IsActiveWindowSeen() {
|
|
|
|
global ID_SEEN
|
|
|
|
WinGet winId, ID, A
|
|
|
|
seen := ID_SEEN.HasKey(winId)
|
|
|
|
ID_SEEN[winId] := true
|
2021-07-01 14:16:25 +00:00
|
|
|
return seen
|
|
|
|
}
|
|
|
|
|
|
|
|
IgnoreArrangementForActiveWindow() {
|
|
|
|
global ARRANGEMENT
|
|
|
|
ARRANGEMENT["ignore"][GetActiveWindowClassPath()] := true
|
|
|
|
SaveArrangement()
|
|
|
|
}
|
|
|
|
|
|
|
|
UnignoreArrangementForActiveWindow() {
|
|
|
|
global ARRANGEMENT
|
|
|
|
ARRANGEMENT["ignore"].Delete(GetActiveWindowClassPath())
|
|
|
|
SaveArrangement()
|
|
|
|
}
|
|
|
|
|
|
|
|
IsActiveWindowIgnore() {
|
|
|
|
global ARRANGEMENT
|
2021-07-05 03:36:29 +00:00
|
|
|
if (ARRANGEMENT["ignore"].HasKey(GetActiveWindowClassPath())) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
; WinGetTitle, title, A
|
|
|
|
; if (title = "") {
|
|
|
|
; return true
|
|
|
|
; }
|
|
|
|
WinGet s, Style, A
|
|
|
|
if (not s & +0xC00000) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
2021-07-01 14:16:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SaveActiveWindowDirection(direction) {
|
|
|
|
global ARRANGEMENT
|
|
|
|
key := GetActiveWindowClassPath()
|
|
|
|
ARRANGEMENT["windows"][key] := direction
|
|
|
|
SaveArrangement()
|
2021-06-30 06:49:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WatchNewWindow() {
|
|
|
|
global ARRANGEMENT
|
|
|
|
Loop {
|
|
|
|
WinWaitActive A ; makes the active window to be the Last Found
|
2021-07-01 14:16:25 +00:00
|
|
|
if not IsActiveWindowSeen() and not IsActiveWindowIgnore() {
|
2021-06-30 06:49:50 +00:00
|
|
|
classPath := GetActiveWindowClassPath()
|
2021-07-01 14:16:25 +00:00
|
|
|
if ARRANGEMENT["windows"].HasKey(classPath) {
|
|
|
|
MoveActiveWinByDirection(ARRANGEMENT["windows"][classPath])
|
2021-06-30 06:49:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
WinWaitNotActive ; waits until the active window changes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2021-06-24 03:16:10 +00:00
|
|
|
|
|
|
|
GetSelectedText() {
|
|
|
|
tmp = %ClipboardAll% ; save clipboard
|
|
|
|
Clipboard := "" ; clear clipboard
|
|
|
|
Send, ^c ; simulate Ctrl+C (=selection in clipboard)
|
|
|
|
ClipWait, 0, 1 ; wait until clipboard contains data
|
|
|
|
selection = %Clipboard% ; save the content of the clipboard
|
|
|
|
Clipboard = %tmp% ; restore old content of the clipboard
|
|
|
|
return selection
|
2021-06-30 06:49:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ShowDebug() {
|
2021-07-05 03:36:29 +00:00
|
|
|
WinGet, s, Style, A
|
|
|
|
if (s & +0xC00000) {
|
|
|
|
SoundBeep, 750, 200
|
|
|
|
}
|
2021-06-30 06:49:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ShowObject(obj) {
|
|
|
|
msg := JSON.Dump(obj)
|
|
|
|
MsgBox, %msg%
|
2021-06-24 03:16:10 +00:00
|
|
|
}
|