为窗口分配热键(并记住大小和位置)。亚洲香港协会

发布于 2024-09-01 13:12:13 字数 1040 浏览 8 评论 0原文

我找到了以下脚本,用于动态地将热键分配给已打开的窗口:(

Code (Expand):
Loop 10
{
   i := A_Index - 1
   HotKey #^%i%,DynHotkey
   HotKey #%i%, DynHotkey
   HotKey #!%i%,DynHotkey
}
Exit

DynHotkey:
   StringRight i, A_ThisHotKey, 1
   StringMid what,A_ThisHotKey, 2, 1
   var := var%i%
   IfEqual what, ^, WinGet var%i%, ID, A  ; Save ID
   Else IfEqual what,!, WinMinimizeAll    ; MinimizeAll
   WinRestore  ahk_id %var%
   WinActivate ahk_id %var%               ; Switch
Return

代码是从此线程复制的 http://www.autohotkey.com/forum/topic38773.html&highlight=dynamic+hot+key)

通过上面的脚本,您可以:

  1. 使用 Win+Ctrl+0 ..9 将热键附加到当前活动窗口。
  2. 使用Win+0..9切换到相应的窗口。

但是,如果我为给定窗口分配一个热键(使用 Win+Ctrl+0..9),然后我想返回到该窗口(Win+0..9),则该窗口将重置为新尺寸和地点。

有没有办法保存尺寸和大小?窗口的位置及其 ID?

如果是的话,剧本会是什么样子?

我在 Windows 7 64 位上运行上述脚本。

多谢,

I have found the following script for dynamically assigning hotkeys to already open windows:

Code (Expand):
Loop 10
{
   i := A_Index - 1
   HotKey #^%i%,DynHotkey
   HotKey #%i%, DynHotkey
   HotKey #!%i%,DynHotkey
}
Exit

DynHotkey:
   StringRight i, A_ThisHotKey, 1
   StringMid what,A_ThisHotKey, 2, 1
   var := var%i%
   IfEqual what, ^, WinGet var%i%, ID, A  ; Save ID
   Else IfEqual what,!, WinMinimizeAll    ; MinimizeAll
   WinRestore  ahk_id %var%
   WinActivate ahk_id %var%               ; Switch
Return

(the code was copied from this thread http://www.autohotkey.com/forum/topic38773.html&highlight=dynamic+hot+key)

With the above script you can:

  1. Use Win+Ctrl+0..9 to attach hotkey to current active window.
  2. Use Win+0..9 to switch to correspoding window.

However, if I assign a hotkey to a given window (using Win+Ctrl+0..9), and then I want I want to go back to that window (Win+0..9), the window is reset to a new size & location.

Is there way of saving the size & location of the window along with it's ID?

If so, what would the script look like?

I am running the above script on Windows 7 64-bit.

Thanks a lot,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花间憩 2024-09-08 13:12:13

您不需要使代码复杂化:)

快速问题:如果您的窗口最小化,您不会有任何问题,对吧?
代码上的“问题”是WinRestore

问题是,如果窗口没有最小化,然后您执行 WinRestore ,它会将大小和位置更改为“未最大化”版本。

仅当窗口最小化时,WinActivate 才会自动执行 WinRestore,因此您可以安全地删除第 16 行(WinRestore 行),因为 WinActivate 将执行您需要的操作。

--编辑--

这就是代码的样子:

Loop 10
{
    i := A_Index - 1
    HotKey #^%i%,DynHotkey
    HotKey #%i%, DynHotkey
    HotKey #!%i%,DynHotkey
}
Exit

DynHotkey:
    StringRight i, A_ThisHotKey, 1
    StringMid what,A_ThisHotKey, 2, 1
    var := var%i%
    IfEqual what, ^, WinGet var%i%, ID, A  ; Save ID
    Else IfEqual what,!, WinMinimizeAll    ; MinimizeAll
    WinActivate ahk_id %var%               ; Switch
Return

我测试了它,它工作得很好。

You dont need to complicate the code :)

Quick question: if your window is minimized you dont have any problems right?
The "problem" on the code is the WinRestore.

The thing is that if the window is not minimized and then you do a WinRestore it will change the size and position to the "not maximized" version of it.

WinActivate automatically does a WinRestore only if the window is minimized, so you can safely remove line 16 (the WinRestore one) since WinActivate will do what you need.

--edit--

this is how the code should look:

Loop 10
{
    i := A_Index - 1
    HotKey #^%i%,DynHotkey
    HotKey #%i%, DynHotkey
    HotKey #!%i%,DynHotkey
}
Exit

DynHotkey:
    StringRight i, A_ThisHotKey, 1
    StringMid what,A_ThisHotKey, 2, 1
    var := var%i%
    IfEqual what, ^, WinGet var%i%, ID, A  ; Save ID
    Else IfEqual what,!, WinMinimizeAll    ; MinimizeAll
    WinActivate ahk_id %var%               ; Switch
Return

I tested it, it works perfectly.

青衫儰鉨ミ守葔 2024-09-08 13:12:13

您可以使用 WinGetPos 读取实际位置并保存。然后就可以使用WinMove来设置位置了。这是一个函数列表: http://www.autohotkey.com/docs/commands.htm< /a>.

You can use WinGetPos to read the actual position and save it. Then you can use WinMove to set the position. Here is a function list: http://www.autohotkey.com/docs/commands.htm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文