窗口最大化后没有显示按键_如何通过一次按键将一台显示器上的所有窗口移动到另一台显示器上

窗口最大化后没有显示按键

In an interesting question here at Experts Exchange, a member asked how to "in Windows 10 move all open windows at once/in one go (i.e., not window by window) from one screen (monitor) to a second screen".

在Experts Exchange上一个有趣的问题中 ,一位成员询问如何“在Windows 10中一次/一次将所有打开的窗口从一个屏幕(监视器)移动到第二个屏幕”

In further clarification, he wants to press a "key combination" (aka a hotkey) to perform the move of all windows from the "primary/first" monitor to the "secondary/second" monitor and, as a "bonus", wants a different "key combination" (hotkey) to perform the move from the second screen back to the first one.

为了进一步说明,他想按下“组合键”(又称热键 )来执行所有窗口从“主要/第一”监视器到“辅助/第二”监视器的移动,并希望将其作为“奖励”。一个不同的“组合键”(热键)来执行从第二个屏幕到第一个屏幕的移动。

This article presents a solution to the member's question. It is a script that I wrote in the AutoHotkey programming/scripting language. If you are not familiar with AutoHotkey, my Experts Exchange article will get you going on it:

本文介绍了该成员的问题的解决方案。 这是我用AutoHotkey编程/脚本语言编写的脚本。 如果您不熟悉AutoHotkey ,那么我在Experts Exchange上的文章将一臂之力

AutoHotkey - Getting Started AutoHotkey-入门

Here is the script in a code block (it is also attached as a file at the end of the article for easy downloading):

这是代码块中的脚本(为了方便下载,该脚本也作为文件附在本文的结尾):

; Joe Winograd 18-Jun-2019
#Warn,UseUnsetLocal ; warning on uninitialized variables
#NoEnv ; avoid checking empty variables to see if they are environment variables
#SingleInstance Force ; replace old instance immediately
SetBatchLines,-1 ; run at maximum speed

!^f:: ; pick whatever hotkey you want - this is Alt+Ctrl+f (stands for First screen)
NewX:=100 ; the X coordinate where all windows will be moved (may be negative)
NewY:=50 ; the Y coordinate where all windows will be moved
Gosub,MoveAllWindows
Return

!^s:: ; pick whatever hotkey you want - this is Alt+Ctrl+s (stands for Second screen)
NewX:=2560 ; the X coordinate where all windows will be moved (may be negative)
NewY:=0 ; the Y coordinate where all windows will be moved
Gosub,MoveAllWindows
Return

MoveAllWindows:
WinGet,AllWindows,List ; get a list of all windows
Loop,%AllWindows% ; loop through all the windows
{
  UniqueID:=AllWindows%A_Index% ; get the unique ID of each window
  WinGetTitle,Title,ahk_id %UniqueID% ; get the Title of each window
  If ((Title="Program Manager") or (Title="")) ; list any exclusions here by adding "or" clauses
    Continue ; this Title has been excluded from moving
  WinGet,MinMaxState,MinMax,ahk_id %UniqueID% ; get the minimized/maximized state of the window
  If (MinMaxState!=0) ; -1 means it is minimized, 1 means it is maximized, 0 means it is neither
    WinRestore,ahk_id %UniqueID% ; if it is minimized or maximized, restore it before moving
  WinMove,ahk_id %UniqueID%,,%NewX%,%NewY% ; move it to its new location
}
Return 

I hope that the descriptive variable names along with the extensive comments in the script provide enough documentation for readers to modify it, but if you have any questions, post them here and I'll try to assist.

我希望描述性的变量名称以及脚本中的广泛注释提供足够的文档供读者修改,但是如果您有任何疑问,请在此处张贴它们,我将尽力提供帮助。

The hotkeys for "move to first monitor" and "move to second monitor" may be any keys that you want. I chose the letters "f" and "s", but you could use numbers, function keys, punctuation, etc. The characters before the key that you choose may be any combination of these four characters (they are called "modifiers"):

对于热键“移动到F IRST监控”和“移动的Econd监视器”可以是任何按键,你想要的。 我选择了字母“ f ”和“ s ”,但可以使用数字,功能键,标点符号等。选择的键之前的字符可以是这四个字符的任意组合(它们称为“修饰符”):

! (exclamation mark) (感叹号) ^ (caret, circumflex, hat) ^ (插入符号,抑扬符,帽子) + (plus sign) + (加号) # (hash mark, pound sign, octothorpe) (井号,井号,八字形)

The modifiers may be in any order. They represent these keys:

修饰符可以是任何顺序。 它们代表以下键:

! is Alt 是Alt ^ is Ctrl ^是Ctrl + is Shift +是Shift # is Win (the Windows logo key) 是Win(Windows徽标键)

As you can see in the source code, I chose Alt+Ctrl+f and Alt+Ctrl+s as the hotkeys, but make them whatever you prefer.

正如您在源代码中看到的那样,我选择了Alt + Ctrl + fAlt + Ctrl + s作为热键,但是可以根据需要选择它们。

The variables for the X and Y coordinates (NewX and NewY) provide total flexibility in where the windows will be moved. Of course, they'll all be moved to the same X/Y coordinates.

XY坐标的变量( NewXNewY )在移动窗口的位置提供了完全的灵活性。 当然,它们都将移至相同的X / Y坐标。

In terms of determining the desired X/Y coordinates, note that there's a script called Window Spy that comes with a standard AutoHotkey installation (the installer places a shortcut to it in the AutoHotkey program group). This is very helpful in figuring out X/Y coordinates on monitors (and determining colors, too). Simply run the script and it brings up this display:

在确定所需的X / Y坐标方面,请注意,标准的AutoHotkey安装附带了一个名为Window Spy的脚本(安装程序将其快捷方式放在AutoHotkey程序组中)。 这对于找出监视器上的X / Y坐标(以及确定颜色)非常有帮助。 只需运行脚本,它将显示以下内容:

窗口最大化后没有显示按键_如何通过一次按键将一台显示器上的所有窗口移动到另一台显示器上_第1张图片

As you move the mouse, the Window Spy dialog shows in real-time the X/Y coordinates (and the color) where the mouse is located. So, to figure out what values you want for NewX and NewY in the script, run Window Spy, move the mouse to the upper left corner of where you want the script to move all the windows, and put the Screen values in the NewX and NewY variables (even though Window Spy says "less often used", the Screen value is what you want in this case).

当您移动鼠标时,“窗口间谍”对话框会实时显示鼠标所在的X / Y坐标(和颜色)。 因此,要弄清楚脚本中要为NewXNewY设置的值,请运行Window Spy,将鼠标移至脚本要移动所有窗口的位置的左上角,然后将Screen值放入NewXNewY变量(即使Window Spy说“不经常使用”,在这种情况下, Screen值也是您想要的)。

I tested the script on W7/64-bit with three monitors and W10/64-bit with two monitors — worked perfectly. In the W7 configuration, the monitor on the left has negative X coordinates, while the monitor on the right has positive X coordinates, and the one in the middle begins with X=0 (and is positive after that).

我在带有三个监视器的W7 / 64位和带有两个监视器的W10 / 64位上测试了脚本-完美地工作了。 在W7配置中,左侧的监视器具有负X坐标,而右侧的监视器具有正X坐标,中间的监视器以X = 0开头(此后为正)。

The script should work in all versions of Windows from XP through W10, both 32-bit and 64-bit, and with any number of monitors. In fact, it even works with only one monitor, moving all the windows to the same X/Y location (for what that's worth). If you run it on a system other than the two I tested, please post your results in a Comment below. Update: I just tested it on an XP/32-bit system with one monitor — worked fine.

该脚本应在从XP到W10的所有Windows版本(32位和64位)以及任何数量的监视器中都可以使用。 实际上,它甚至只用一个监视器工作,将所有窗口移动到相同的X / Y位置(这值得)。 如果您在我测试过的两个系统以外的系统上运行它,请在下面的评论中发布您的结果。 更新:我刚刚在带有一个监视器的XP / 32位系统上对其进行了测试-正常工作。

Article update on 19-Jun-2019 shortly after initial publication

首次发布后不久,2019年6月19日更新文章

During the publication review process, the Article Editor, Andrew Leniart, tested the script on his W10 system and came up with some great comments/questions that I'll address here.

在发布审阅过程中,文章编辑器Andrew Leniart在他的W10系统上测试了该脚本,并提出了一些很棒的评论/问题,我将在这里解决。

• If a window is in a Minimized or Maximized state, the script does a Restore before moving it (see lines 27-29 in the attached script). In the case of Minimized, doing the Restore is necessary, because the WinMove command cannot move a Minimized window. In the case of a Maximized window, it is not necessary to do a Restore, but moving a Maximized window to a larger size screen results in the Maximized indicator in the window (upper right corner, middle icon), but the window is not really maximized on the larger screen. To avoid this undesirable behavior, I chose to do a Restore on a Maximized window. If you prefer not to do that, change line 28 in the script to this:

•如果窗口处于“ 最小化”或“ 最大化”状态,则脚本会在移动窗口之前执行“还原”操作 (请参阅所附脚本中的第27-29行)。 在最小化的情况下,必须执行还原 ,因为WinMove命令不能移动最小化窗口。 在最大化窗口的情况下,不必执行还原操作 ,但是将最大化窗口移至更大尺寸的屏幕会导致窗口中出现最大化指示符(右上角,中间图标),但是该窗口并非真正在更大的屏幕上最大化。 为了避免这种不良行为,我选择在 最大化”窗口上进行“还原” 。 如果您不想这样做,请将脚本中的第28行更改为:

If (MinMaxState=-1) ; -1 means it is minimized, 1 means it is maximized, 0 means it is neither

如果(MinMaxState = -1); -1表示已最小化,1表示已最大化,0表示两者都不是

• If a window is not visible (by intention), doing the Restore on the Minimized window is likely to make it visible when it is moved to the other monitor. If you do not want this to happen, exclude the window from being moved by putting another "or" clause in the "If" statement on line 25 of the script, such as:

•如果一个窗口不可见(故意),则在最小化窗口上执行“ 还原”时,可能会将其移至另一台显示器时使其可见。 如果您不希望这种情况发生,请通过在脚本第25行的“ If”语句中放置另一个“或”子句来排除移动窗口的麻烦,例如:

If ((Title="Program Manager") or (Title="Task Scheduler") or (Title=""))

如果是((Title =“ Program Manager”)或(Title =“ Task Scheduler”)或(Title =“”))

You may need more complex logic than the equality test shown above if, for example, the Title needs to start with a string or contain a string.

例如,如果标题需要以字符串开头或包含字符串,则可能需要比上面显示的相等性测试更复杂的逻辑。

Another idea is to modify the script to save the MinMax state of each window prior to moving it and then reestablish that state after moving it. I'll leave that to the motivated reader. :)

另一个想法是修改脚本以在移动每个窗口之前保存每个窗口的MinMax状态,然后在移动它之后重新建立该状态。 我将其留给有动力的读者。 :)

• Be sure to change the NewX and NewY variables on lines 8, 9, 14, 15 in the script so that they are appropriate for your system and move the windows where you want them. Inappropriate values for NewX and NewY will likely result in strange, undesirable movement.

•确保更改脚本中第 8、9、14、15行的NewXNewY变量,以使其适合您的系统,并将窗口移至所需位置。 NewXNewY的不合适会导致奇怪的不良运动。

• This is an extremely simple, lightweight solution. The entire script (not counting blank lines and comments) is only 28 lines of code. It is, of course, not meant to compete with the likes of DisplayFusion and UltraMon, which are large, robust programs with tons of features. My program, by design, does not even have the tiniest fraction of those programs' functionality.

•这是一个非常简单,轻便的解决方案。 整个脚本(不计空白行和注释)仅28行代码。 当然,它并不意味着要与DisplayFusion和UltraMon之类的产品竞争,后者是具有大量功能的大型,强大程序。 从设计上来说,我的程序甚至没有这些程序功能中最微小的部分。

My thanks to Andrew for his feedback during the publication process. The changes above that were inspired by his feedback have resulted in an improved article.

感谢安德鲁在出版过程中的反馈。 受到他的反馈启发而产生的上述变化导致了文章的改进。

If you find this article to be helpful, please click the thumbs-up icon below. This lets me know what is valuable for EE members and provides direction for future articles. Thanks very much! Regards, Joe

如果您发现本文有帮助,请单击下面的大拇指图标。 这使我知道什么对EE成员有价值,并为以后的文章提供了指导。 非常感谢! 问候乔

MoveAllWindows.ahk

MoveAllWindows.ahk

翻译自: https://www.experts-exchange.com/articles/33613/How-to-move-all-windows-on-one-monitor-to-another-monitor-with-a-single-keystroke.html

窗口最大化后没有显示按键

你可能感兴趣的:(窗口最大化后没有显示按键_如何通过一次按键将一台显示器上的所有窗口移动到另一台显示器上)