📜  ahk 启用多显示器 (1)

📅  最后修改于: 2023-12-03 15:13:17.200000             🧑  作者: Mango

AHK启用多显示器

在多显示器环境下,使用AHK可以轻松地实现多个显示器之间的切换和拖拽窗口等操作。下面是AHK启用多显示器的几个方面。

获得显示器数量

为了获知当前系统中显示器的数量,可以使用以下函数:

SysGet, numMonitors, MonitorCount

其中numMonitors为变量名,MonitorCount为指定的参数。

使用示例:

SysGet, numMonitors, MonitorCount

MsgBox %numMonitors%
显示器的工作区

显示器的工作区是指当前显示器可以使用的可视区域,通常不包括任务栏或桌面图标。

以下函数可以用于获取显示器的工作区:

SysGet, MonitorWorkArea, MonitorWorkArea, %monitorIndex%

其中MonitorWorkArea为变量名,%monitorIndex%为显示器的序号。如果省略显示器序号,则返回所有显示器的工作区。

使用示例:

SysGet, numMonitors, MonitorCount

Loop %numMonitors%
{
    SysGet, monitorWorkArea, MonitorWorkArea, %A_Index%
    
    MsgBox %monitorWorkArea%
}
窗口移动到指定显示器

窗口移动到指定显示器的方法如下:

WinMove, ahk_id %window_handle%, X, Y, Width, Height

其中ahk_id %window_handle%为指定的窗口句柄,XY为窗口左上角坐标,WidthHeight为窗口宽度和高度。

使用示例:

SysGet, numMonitors, MonitorCount

Loop %numMonitors%
{
    SysGet, monitorWorkArea, MonitorWorkArea, %A_Index%
    
    WinMove, ahk_id %window_handle%, monitorWorkAreaLeft, monitorWorkAreaTop
}
窗口移动到相邻显示器

窗口移动到相邻显示器的方法如下:

WinGetPos, winX, winY, winWidth, winHeight, ahk_id %window_handle%
SysGet, currentMonitor, MonitorFromPoint, %winX% , %winY%

if (currentMonitor < numMonitors)
{
    SysGet, targetMonitorWorkArea, MonitorWorkArea, %currentMonitor% + 1
}
else
{
    SysGet, targetMonitorWorkArea, MonitorWorkArea, 1
}

WinMove, ahk_id %window_handle%, targetMonitorWorkAreaLeft, targetMonitorWorkAreaTop

上述代码首先获取了当前窗口所在的显示器,然后计算出左边或右边的显示器,并将窗口移动到该显示器。

打开程序时指定窗口出现在哪个显示器

使用Run命令打开程序时,可以使用以下参数来指定窗口出现的显示器:

Run, "D:\Program Files\Notepad++\notepad++.exe", , , WinSet, Region, 2

其中Region参数可以指定窗口在哪个区域显示。如果为2,则表示在第二个屏幕上显示。

以上就是AHK启用多显示器的几个方面。使用AHK可以轻松地管理多个显示器,并且大大提高了工作效率。