为窗口分配热键(并记住大小和位置)。亚洲香港协会
我找到了以下脚本,用于动态地将热键分配给已打开的窗口:(
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)
通过上面的脚本,您可以:
- 使用 Win+Ctrl+0 ..9 将热键附加到当前活动窗口。
- 使用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:
- Use Win+Ctrl+0..9 to attach hotkey to current active window.
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要使代码复杂化:)
快速问题:如果您的窗口最小化,您不会有任何问题,对吧?
代码上的“问题”是
WinRestore
。问题是,如果窗口没有最小化,然后您执行
WinRestore
,它会将大小和位置更改为“未最大化”版本。仅当窗口最小化时,WinActivate 才会自动执行 WinRestore,因此您可以安全地删除第 16 行(WinRestore 行),因为 WinActivate 将执行您需要的操作。
--编辑--
这就是代码的样子:
我测试了它,它工作得很好。
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:
I tested it, it works perfectly.
您可以使用 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.