按住CapsLock, 可在窗口的任意位置用鼠标左键拖动窗口,用滚轮调整窗口大小

/*
@Require AutoHotkey V2.0+
@Version 0.2
@Description 按住CapsLock, 可在窗口的任意位置用鼠标左键拖动窗口,用滚轮调整窗口大小
*/

CapsLock & LButton:: {  ;  By Tebayaki
  DllCall("GetCursorPos", "int64*", &cursorPt := 0)
  childHwnd := DllCall("WindowFromPoint", "int64", cursorPt, "ptr")
  if 0 == topHwnd := DllCall("GetAncestor", "ptr", childHwnd, "uint", 2, "ptr")
    return
  DllCall("ShowWindowAsync", "ptr", topHwnd, "int", 1)
  WinActivate(topHwnd)
  WinGetPos(&topWndX, &topWndY, , , topHwnd)
  offsetX := (cursorPt & 0xffffffff) - topWndX
  offsetY := (cursorPt >> 32) - topWndY
  pLowLevelKeyboardProc := CallbackCreate(LowLevelKeyboardProc, "F")
  hook := DllCall("SetWindowsHookEx", "int", 14, "ptr", pLowLevelKeyboardProc, "ptr", 0, "uint", 0, "ptr")
  LowLevelKeyboardProc(nCode, wParam, lParam) {
    Critical
    if 0 == nCode {
      if 0x0200 == wParam
        DllCall("SetWindowPos", "ptr", topHwnd, "ptr", 0, "int", NumGet(lParam, "int") - offsetX, "int", NumGet(lParam, 4, "int") - offsetY, "int", 0, "int", 0, "uint", 1)
      else if 0x0202 == wParam {
        DllCall("UnhookWindowsHookEx", "ptr", hook)
        CallbackFree(pLowLevelKeyboardProc)
      }
    }
    return DllCall("CallNextHookEx", "ptr", 0, "int", nCode, "ptr", wParam, "ptr", lParam)
  }
}

CapsLock & WheelUp:: {
  divisor := 15
  DllCall("GetCursorPos", "int64*", &cursorPt := 0)
  childHwnd := DllCall("WindowFromPoint", "int64", cursorPt, "ptr")
  if 0 == topHwnd := DllCall("GetAncestor", "ptr", childHwnd, "uint", 2, "ptr")
    return
  DllCall("SetForegroundWindow", "ptr", topHwnd)
  WinGetPos(&topWndX, &topWndY, &topWndW, &topWndH, topHwnd)
  rateX := ((cursorPt & 0xffffffff) - topWndX) / topWndW
  rateY := ((cursorPt >> 32) - topWndY) / topWndH
  addendW := A_ScreenWidth / divisor
  addendH := A_ScreenWidth * (topWndH / topWndW) / divisor
  topWndX -= addendW * rateX
  topWndY -= addendH * rateY
  topWndW += addendW
  topWndH += addendH
  DllCall("SetWindowPos", "ptr", topHwnd, "ptr", 0, "int", topWndX, "int", topWndY, "int", topWndW, "int", topWndH, "uint", 0)
}

CapsLock & WheelDown:: {
  divisor := 15
  DllCall("GetCursorPos", "int64*", &cursorPt := 0)
  childHwnd := DllCall("WindowFromPoint", "int64", cursorPt, "ptr")
  if 0 == topHwnd := DllCall("GetAncestor", "ptr", childHwnd, "uint", 2, "ptr")
    return
  DllCall("SetForegroundWindow", "ptr", topHwnd)
  WinGetPos(&topWndX, &topWndY, &topWndW, &topWndH, topHwnd)
  rateX := ((cursorPt & 0xffffffff) - topWndX) / topWndW
  rateY := ((cursorPt >> 32) - topWndY) / topWndH
  addendW := A_ScreenWidth / divisor
  addendH := A_ScreenWidth * (topWndH / topWndW) / divisor
  topWndX += addendW * rateX
  topWndY += addendH * rateY
  topWndW -= addendW
  topWndH -= addendH
  DllCall("SetWindowPos", "ptr", topHwnd, "ptr", 0, "int", topWndX, "int", topWndY, "int", topWndW, "int", topWndH, "uint", 0)
}

 

声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。