Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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.
- ; sorts a given array
- sort(array) { ; Function initialization
- sorted := false ; Variable used to decide if the array is alphabetized yet: false, because it isn't
- While !sorted ; Beginning of loop
- {
- swapped := false ; Variable that decides if any swapping occurred: false, because it hasn't yet
- Loop, % array.MaxIndex() { ; Loops through for the max amount of array items
- i := A_Index ; This is just for convenience, so I don't have to type A_Index multiple times
- j := i + 1
- if (i < array.MaxIndex()) { ; Obviously only checking if A_Index is less than number of items in arrayD
- if (array[i] > array[j]) { ; AHK allows < and > for alphabetical strings
- tempVal := array[j] ; Holds onto the array value that we'll be moving
- array.RemoveAt(j) ; Deletes that value from the array
- array.InsertAt(i, tempVal) ; Inserts it into the previous position
- swapped := true ; Set to true, because a swap happened
- }
- }
- }
- if !swapped ; If no swaps happened...
- sorted := true ; then we can exit the loop, otherwise, it repeats the process
- }
- return array ; returns the sorted array
- }
- ; finds the monitor number that the selected window is on (NOTE: this only works if your
- ; monitors are arranged horizontally. You'll have to make some changes if you want it
- ; to work for vertically arranged monitors, and even more so to work for monitors arranged
- ; vertically and horizontally)
- getMonitorNumber() {
- ;80 is the code for the SM_CMONITORS sub-command. Retrieves # of display monitors
- SysGet, numMon, 80
- ; init MonLeftArray to store all X coords of monitors. Indexes correspond to monitor number
- MonLeftArray := Object()
- MonLeftArray.SetCapacity(numMon)
- ; populate MonLeftArray
- Loop, %numMon% {
- i := A_Index
- SysGet, mon, Monitor, %i%
- MonLeftArray[i] := monLeft
- }
- ; init SortedMonLeftArray to store an ordered array of X coords
- SortedMonLeftArray := Object()
- SortedMonLeftArray.SetCapacity(numMon)
- ; populate SortedMonLeftArray
- Loop, %numMon% {
- i := A_Index
- SysGet, mon, Monitor, %i%
- SortedMonLeftArray[i] := monLeft
- }
- ; sort SortedMonLeftArray
- SortedMonLeftArray := sort(SortedMonLeftArray)
- ; get the data of selected window
- WinGetPos,X,Y,W,H,A,,,
- ; find where the selected window is
- Loop, %numMon% {
- i := A_Index
- ; is %i% the first index? and is X before this index?
- if (i = 1 and X < SortedMonLeftArray[1]) {
- currMonLeft := SortedMonLeftArray[i]
- break
- }
- ; is %i% the last index?
- if (i + 1 > numMon) {
- currMonLeft := SortedMonLeftArray[i]
- }
- ; %i% is not the last index. There is a next monitor.
- else {
- j := i + 1
- ; there are eight pixels of padding in windows for some reason
- if (SortedMonLeftArray[i] <= X + 8 and X + 8 < SortedMonLeftArray[j]) {
- currMonLeft := SortedMonLeftArray[i]
- break
- }
- }
- }
- ; find which monitor corresponds to currMonLeft
- Loop, %numMon% {
- i := A_Index
- if (MonLeftArray[i] = currMonLeft) {
- return i
- }
- }
- }
- ; Move window up (Windows + Shift + UP)
- +#Up::
- monNumber := getMonitorNumber()
- ; get the work area of active monitor
- SysGet, mon, MonitorWorkArea, %monNumber%
- ; move window
- WinMove,A,,monLeft, 0, (monRight - monLeft), (monBottom/2)
- return
- ; Move window down (Windows + Shift + DOWN)
- +#Down::
- monNumber := getMonitorNumber()
- ; get the work area of active monitor
- SysGet, mon, MonitorWorkArea, %monNumber%
- ; move window
- WinMove,A,,monLeft, monBottom/2 , (monRight - monLeft), (monBottom/2)
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement