Skip to content

Adaption for AHKv2 #3

Description

@mtness

Here, i adapted it for AHKv2

; Centers any active window to the screen.
; Press Win+C to center any window.
; Created September 2019
; Migrated to AHKv2 June 2026

; Created by Wesley Pyburn (TroubleChute)
; https://github.com/TcNoco/TcNo-Random-Scripts

#c:: {
    ; Get the active window's ID
    activeID := WinExist("A")
    
    ; Get the window's size
    WinGetPos(, , &sizeW, &sizeH, activeID)
    
    ; Get the work area of the monitor containing the window
    MonitorGetWorkArea(, &waLeft, &waTop, &waRight, &waBottom)
    
    waWidth  := waRight - waLeft
    waHeight := waBottom - waTop
    
    ; Calculate centered position
    newX := waLeft + (waWidth / 2) - (sizeW / 2)
    newY := waTop + (waHeight / 2) - (sizeH / 2)
    
    ; Move the window
    WinMove(newX, newY, , , activeID)
}

Best regards, MT

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions