2016-03-18 28 views
-1

我一直使用一个简短的AutoHotKey脚本来模拟Windows 10上的Alt Tab,使用鼠标中键,这样我就可以快速打开我最近打开的应用程序,或者通过单击按钮快速打开两个应用程序。这是我使用的是什么使用AutoHotKey切换到ACTIVE监视器中最近打开的应用程序?

Mbutton::SendEvent {Alt Down}{Tab}{Alt Up} 

但我一直在使用两台显示器最近,和我真正想要做的是切换到最近打开的应用程序上的活动监视器(或监视器鼠标目前正在开启)。单独使用Alt Tab不起作用,因为通常最近打开的应用程序在另一个显示器上,而且我只想将最近使用的应用程序的窗口向前移动,如果它位于我目前正在使用的显示器中。任何人都知道这是否可能,以及我会如何去做?

+0

我可以想象,你可以编写一个脚本,跟踪四个窗口(如果是两个监视器)窗口 - 每个监视器最后打开的两个窗口。它会定期检查并更新它们。当按下热键时,它应该检测当前监视器,当前窗口是什么,然后检查此监视器最近的两个窗口列表。如果第一个与当前激活的相同,它将切换到第二个;不是 - 到两个中的第一个。 – stansult

+0

谢谢,是的,这是我认为可能会发挥作用的东西。问题是我无法从头开始做!我希望能在网上找到能适应的东西,但还没有。 – omaxio

+0

这不会很简单。这里是你如何可以检查窗口是在哪个屏幕上:http://stackoverflow.com/questions/34338637/determining-which-screen-a-window-is-on-by-checking-where-the-most-surfacearea – Forivin

回答

0

我在这里粘贴我的脚本。这是非常丑陋的,但它可以像你所描述的那样在我的双显示器设置上工作:切换到上一个(用于单击中间按钮的显示器)活动窗口。

#WinActivateForce 
#SingleInstance 
#Persistent 

CoordMode, Mouse, Screen 
CoordMode, ToolTip, Screen 

DetectHiddenWindows, On 
SetTitleMatchMode , 2 
SetBatchLines , -1 
SetWorkingDir %A_ScriptDir% 

Thread, interrupt, 0 
SetTimer, UpdateCurrentWindow, 100 

isDebug := true 

SysGet, monitors_total, MonitorCount 
SysGet, monitor_primary, MonitorPrimary 

Hotkey, MButton, SwitchToLastWindow, On 

return 


SwitchToLastWindow: 

WinGet, active_id, ID, A 

Loop , %monitors_total% 
{ 
    if (A_Index != current_monitor) 
     continue 

    switch_to_window := (active_id = winlast%A_Index%) 
         ? winprelast%A_Index% 
         : winlast%A_Index% 
} 

WinActivate , ahk_id %switch_to_window% 

return 



UpdateCurrentWindow: 

WinGet, active_id, ID, A 
monitor_index := GetMonitorIndexFromWindow(active_id) 

current_monitor := GetMonitorIndexFromMouse() 

if (monitor_index > monitors_total) 
    monitors_total := monitor_index 

if (winlast%monitor_index% != active_id) 
{ 
    winprelast%monitor_index% := winlast%monitor_index% 
    winlast%monitor_index% := active_id 
} 

if isDebug 
{ 
    DebugToolTip := "" 
    Loop , %monitors_total% 
    { 
     DebugToolTip .= "Monitor # " . A_Index 
        . ":`n`nLast window: " . winlast%A_Index% 
        . "`nPre-last window: " . winprelast%A_Index% . "`n`n" 
    } 

    MouseGetPos, xpos, ypos 
    DebugToolTip .= "x: " . xpos . "`ny: " . ypos . "`ncurrent_monitor: " . current_monitor 
       . "`n`nA_ScreenHeight: " . A_ScreenHeight . "`nA_ScreenWidth: " . A_ScreenWidth 
       . "`n`nmonitors_total: " . monitors_total . "`nmonitor_primary: " . monitor_primary 

    ToolTip , %DebugToolTip%, 10, 10 
} 

return 


; only done for one case: total 2 monitors, monitor to the left is primary 
; need to redo for the generic case 

GetMonitorIndexFromMouse() 
{ 
    SysGet, monitors_total, MonitorCount 
    SysGet, monitor_primary, MonitorPrimary 
    MouseGetPos, xpos, ypos 
    current_monitor := (xpos > A_ScreenWidth) ? 2 : 1 

    return current_monitor 
} 


; this function is from autohotkey.com/board/topic/69464-how-to-determine-a-window-is-in-which-monitor/?p=440355 

GetMonitorIndexFromWindow(windowHandle) 
{ 
    ; Starts with 1. 
    monitorIndex := 1 

    VarSetCapacity(monitorInfo, 40) 
    NumPut(40, monitorInfo) 

    if (monitorHandle := DllCall("MonitorFromWindow", "uint", windowHandle, "uint", 0x2)) 
     && DllCall("GetMonitorInfo", "uint", monitorHandle, "uint", &monitorInfo) 
    { 
     monitorLeft := NumGet(monitorInfo, 4, "Int") 
     monitorTop := NumGet(monitorInfo, 8, "Int") 
     monitorRight := NumGet(monitorInfo, 12, "Int") 
     monitorBottom := NumGet(monitorInfo, 16, "Int") 
     workLeft  := NumGet(monitorInfo, 20, "Int") 
     workTop  := NumGet(monitorInfo, 24, "Int") 
     workRight  := NumGet(monitorInfo, 28, "Int") 
     workBottom := NumGet(monitorInfo, 32, "Int") 
     isPrimary  := NumGet(monitorInfo, 36, "Int") & 1 

     SysGet, monitorCount, MonitorCount 

     Loop, %monitorCount% 
     { 
      SysGet, tempMon, Monitor, %A_Index% 

      ; Compare location to determine the monitor index. 
      if ((monitorLeft = tempMonLeft) and (monitorTop = tempMonTop) 
       and (monitorRight = tempMonRight) and (monitorBottom = tempMonBottom)) 
      { 
       monitorIndex := A_Index 
       break 
      } 
     } 
    } 

    return monitorIndex 
} 

上述功能之一(GetMonitorIndexFromWindow(windowHandle))不是我的,采取from here

请注意,我没有时间去处理我的GetMonitorIndexFromMouse()函数的泛型情况,所以它对我的特定情况(2个监视器,以左侧为主)有好处。

我在这里有isDebug := true,所以你可以看到带有变量的工具提示 - 当然,如果脚本适用于你,可以随意更改为isDebug := false

+1

很酷,感谢您花时间做到这一点! – omaxio

+0

没问题,这很有趣:) – stansult

相关问题