Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #SingleInstance ;force
- TraySetIcon "AHK-altdrag.ico"
- ; #NoTrayIcon
- #UseHook
- SetWinDelay 5 ; ms - default 100ms
- ; CoordMode "Mouse", "Screen" ; causes craziness, leave it default ("Client") for now
- ; KeyHistory
- ; ********************************************* ; Customize your
- ; *************** BUTTONS SETUP *************** ; trigger hotkey &
- ; ********************************************* ; Mouse buttons here
- global Trigger_Hotkey:= ">^" ; must be symbol prefix
- ; (like: ^ or >! )
- ; (NOT Ctrl or RAlt )
- global Mousebtn_Move := "LButton"
- global Mousebtn_Resize := "MButton"
- global Mousebtn_Minimize := "RButton"
- global Mousebtn_Close := "XButton1"
- ; global Mousebtn_AlwaysOnTop := "XButton2"
- global Mousebtn_extra := "XButton2"
- ; *********************************************
- ; *********************************************
- ; *********************************************
- ;_________________________________________________________________________________________________
- ;------------------------------------------------ HOTKEY INSTANTIATION
- ; Hotkey Trigger_Hotkey Mousebtn_Move, "MoveWindow" ; Move
- >^Lbutton:: MoveWindow()
- ; Hotkey Trigger_Hotkey Mousebtn_Resize, "ResizeWindow" ; Resize
- >^Mbutton:: ResizeWindow()
- Hotkey Trigger_Hotkey Mousebtn_Minimize, "MinimizeWindow" ; Minimize
- Hotkey Trigger_Hotkey Mousebtn_Close, "CloseWindow" ; Close
- ; Hotkey Trigger_Hotkey Mousebtn_AlwaysOnTop, "AlwaysOnTop" ; Set always on top
- Hotkey Trigger_Hotkey Mousebtn_extra, "SendToBottom" ; Send to bottom
- ;--------------------------------------------------------------------------------
- >^WheelUp::Volume_Up ; Volume wheel
- >^WheelDown::Volume_Down
- ;--------------------------------------------------------------------------------
- !MButton:: ; Send window to bottom
- !#^+F22:: ;;;;;;;;;;; <--see *NOTE-TOUCHPAD*
- SendToBottom()
- return
- ; *******************************************************
- ; * *NOTE-TOUCHPAD* *
- ; * *
- ; * When using a touchpad on a lot of laptops, Windows *
- ; * simulates a middle-click using Win+Ctrl+Shift+F22 *
- ; * instead of sending the "true" MButton signal. *
- ; * *
- ; * That's why it's necessary to set up another shortcut*
- ; * for that key combination, so a 3-finger touch on a *
- ; * laptop touchpad will work the same as on a mouse. *
- ; *******************************************************
- ;_________________________________________________________________________________________________
- ;------------------------------------------------ GLOBAL VARS/FUNCTIONS
- global X:=0,Y:=0,winW:=0,winH:=0,winID:=0
- MouseSetWinID() {
- MouseGetPos ,, winID
- }
- MouseSetWinIDAndCoordsActivate() {
- ; bring to front, make transparent
- MouseGetPos X,Y,winID ; (X,Y RELATIVE TO ACTIVE CLIENT WINDOW)
- WinActivate "ahk_id " winID
- WinWaitActive "ahk_id " winID
- }
- ;_________________________________________________________________________________________________
- ;------------------------------------------------ Actions: SIMPLE ACTIONS
- MinimizeWindow() {
- MouseSetWinID(), WinMinimize("ahk_id " winID), exit()
- }
- CloseWindow() {
- MouseSetWinID(), WinClose(winID), exit()
- }
- SetAlwaysOnTop() {
- MsgBox("Donelol")
- }
- SendToBottom() {
- MouseSetWinID(), WinMoveBottom("ahk_id " winID), exit()
- }
- ;_________________________________________________________________________________________________
- ;------------------------------------------------ Actions: RESIZE
- ResizeWindow() {
- MouseSetWinIDAndCoordsActivate()
- ; WinGetPos ,,winW,winH,"ahk_id " winID
- ;------------------------------------------ ----------
- ; MenuSelect("ahk_id winID",, "0&", "Size") ; unstable
- ;------------------------------------------ ----------
- ; sends a message directly to the OS
- WM_SYSCOMMAND := 0x112 ; Window's "system menu" (alt+space)
- SC_SIZE := 0xF000 ; - previously 0x05 ; Resize function
- PostMessage WM_SYSCOMMAND, SC_SIZE,0,, "ahk_id " winID
- Sleep 50
- WinGetPos ,,winW,winH,"ahk_id " winID
- ; Freeze the cursor for a sec
- ;DllCall( "ClipCursor", UInt,&R ) : DllCall( "ClipCursor" )
- ; https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-clipcursor
- ; autohotkey.com/board/topic/44588-restrict-mouse-move-to-area/?p=277613
- ; ----------------------------------------------------------------------
- ; the '*' is Wildcard: Fire the hotkey even if extra modifiers are being held down.
- ; *ScrollLock:: ; Hotkey will toggle status, scroll-lock key
- ; Confine := !Confine
- ;
- ; ClipCursor( Confine, 0, 50, A_screenwidth, A_screenheight)
- ; Return
- ;
- ;
- ; ClipCursor( Confine=True, x1=0 , y1=0, x2=1, y2=1 ) {
- ; VarSetCapacity(R,16,0), NumPut(x1,&R+0),NumPut(y1,&R+4),NumPut(x2,&R+8),NumPut(y2,&R+12)
- ; Return Confine ? DllCall( "ClipCursor", UInt,&R ) : DllCall( "ClipCursor" )
- ; }
- ; for reference, I got the script from here
- ;Is there a way to use AHK to effectively ignore the y-axis while still retaining full x-axis ;functionality?
- ;
- ;http://www.autohotkey.com/forum/topic42365.html&highlight=draw+mouse
- ; Which quadrant are we in? (this part needs keyboard hook REAL BAD)
- Send X<(winW/2) ? "{Left}" : "{Right}" ; Left half?
- Sleep 50
- Send Y<(winH/2) ? "{Up}" : "{Down}" ; Upper half?
- ; Switch {
- ; Case X<(winW/2) AND Y<(winH/2): Send "{Left}{Up}" ;upper-left corner
- ; Case X>(winW/2) AND Y<(winH/2): Send "{Right}{Up}" ;upper-right corner
- ; Case X<(winW/2) AND Y>(H/2): Send "{Left}{Down}" ;lower-left corner
- ; Default: Send "{Right}{Down}" ;lower-right corner
- ; }
- ; OnMessage(0x232, ()=>WinSetTransparent("off", "ahk_id " winID)) ; WM_EXITSIZEMOVE
- ; OnMessage(0x232, "SetAlwaysOnTop") ; WM_EXITSIZEMOVE
- WinSetTransparent "off", "ahk_id " winID
- }
- ;_________________________________________________________________________________________________
- ;------------------------------------------------ Actions: MOVE
- MoveWindow() {
- MouseSetWinIDAndCoordsActivate() ; sets: X,Y coords/winID of mouse cursor
- WinSetTransparent 215, "ahk_id " winID
- if WinGetMinMax()
- WinRestore
- ;-------------TODO?---------------------------
- ; additional MButton click -> toggle Maximized
- ; Hotkey Mousebtn_Resize, ()=>WinMaximize("ahk_id " winID), "On"
- ;---------------------------------------------
- ; Get initial mouse position (RELATIVE TO ACTIVE CLIENT WINDOW)
- ; Xstart:=0,Ystart:=0
- ; MouseGetPos Xstart, Ystart
- ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ deprecated if mousegetpos() is in global method
- ; Set X/Y vars ahead of time(for performance; see below inside loop) [DEPRECATED!!!]
- Xstart := X, Ystart := Y
- ; X := Xstart, Y := Ystart
- ; Get initial Window position
- WinGetPos winX, winY,,, "ahk_id " winID
- ; distanceBetween = ????????????????????
- ; Record current MoveButton state <------------- SEE *NOTE-MOVEBUTTONSTATE*
- StartState := GetKeyState(Mousebtn_Move, "P")
- while StartState = GetKeyState(Mousebtn_Move, "P")
- {
- ; update current mouse position
- MouseGetPos X, Y
- ; Calculate new window position
- winX += X-Xstart, winY += Y-Ystart
- ; you really want to ADD to the existing winX/Y vars, rather than
- ; reassign them, because AHK rips open a new memory address for every
- ; variable reassignment (just like Python), causing performance issues
- ; when doing it again & again in every loop iteration
- ; NOTE: at least, I think that's how it works... :/
- ; TODO: borders (/snapping) stuff
- WinMove winX, winY,,, "ahk_id " winID
- }
- WinSetTransparent "off", "ahk_id " winID
- ; Hotkey Mousebtn_Resize, , "Off"
- ; *******************************************************
- ; * *NOTE-MOVEBUTTONSTATE* *
- ; * *
- ; * This flag helps when using programs that simulate *
- ; * the first click, like GestureSign - because in those*
- ; * cases the btn's "pressed" state will only show "0" *
- ; * (whereas a real mouse always shows "1") - until you *
- ; * click again. Therefore we'd rather check when the *
- ; * first button's state has been TOGGLED, rather than *
- ; * absolute down/up. *
- ; * *
- ; * This way, you just need another tap/click to break *
- ; * the loop. Regular mice will still break the loop *
- ; * normally upon btn release. *
- ; *******************************************************
- }
Advertisement
Add Comment
Please, Sign In to add comment