放大当前窗口,恢复旧窗口的先前大小和位置

时间:2015-11-12 02:15:17

标签: autohotkey

我试图构建一个基本上简单的脚本:

  1. 检查活动窗口是否在一段时间内发生了变化
  2. 如果已经改变了 一个。我希望鼠标下的窗口调整大小并移动
    湾恢复最后一个缩放窗口的位置(所以我当时只能有一个缩放窗口)
  3. 我写了这个简单的剧本,但是我错过了一些东西,窗户闪烁,我不知道为什么

    #NoEnv
    #Persistent
    SetTitleMatchMode, 2
    
    SetTimer, tableDiff, 1000
    
    firstRun := 0
    return
    
    tableDiff:
    if (firstRun <> 0)
        {
        winUnderMouseLast := winUnderMouseCurrent
        WinGetTitle, titleLast, ahk_id %winUnderMouseLast%
        WinGetClass, classLast, ahk_id %winUnderMouseLast%
        WinGetPos, xLast, yLast, wLast, hLast, ahk_id %winUnderMouseLast%
        }
    else
    msgbox, 1st run
    
    
    MouseGetPos,,,winUnderMouseCurrent
    WinGetTitle, titleCurrent, ahk_id %winUnderMouseCurrent%
    WinGetClass, classCurrent, ahk_id %winUnderMouseCurrent%
    WinGetPos, xCurrent, yCurrent, wCurrent, hCurrent, ahk_id %winUnderMouseCurrent%
    
    If (winUnderMouseLast != winUnderMouseCurrent)
     {
        winMove, ahk_id %winUnderMouseLast%,,%xLast%,%yLast%
    
        ;msgbox, Current %titleCurrent%  Last %titleLast%
        WinMove, ahk_id %winUnderMouseCurrent%,, 421, 156, 1016, 727
    
     }
    
    firstRun := 1
    return
    

1 个答案:

答案 0 :(得分:1)

使用WinWaitNotActive代替计时器:

loop {
    winwaitnotactive, % "ahk_id " winExist("A")
    mousegetpos,,,id

    if (lastID)
        winmove, ahk_id %lastID%,, x,y,w,h

    wingetpos, x,y,w,h, ahk_id %id%
    winmove, ahk_id %id%,, 421, 156, 1016, 727
    lastID := id
}