如何用autohotkey给当前窗口绑定一个快捷键,想要切换到这个窗口,只要按这个快捷键就可以了?

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: 如何用autohotkey给当前窗口绑定一个快捷键,想要切换到这个窗口,只要按这个快捷键就可以了?

Re: 如何用autohotkey给当前窗口绑定一个快捷键,想要切换到这个窗口,只要按这个快捷键就可以了?

Post by llinfeng » 12 May 2017, 04:20

没有仔细看你的code,但我目前在用如下的脚本自由切换不同程序、甚至不同程序的不同窗口(session)

Code: Select all

; 首先,在最最开始的地方,放这样的定义(定义 group)
groupadd , FIRE              , ahk_exe Firefox.exe
return

; 然后,就可以用 Win+3来激活Firefox(甚至是其不同的session/窗口)。
#3::
IfWinExist ahk_exe firefox.exe
    groupactivate, FIRE, r
else
	run "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
return
该是部分解决了你的问题?

Re: 如何用autohotkey给当前窗口绑定一个快捷键,想要切换到这个窗口,只要按这个快捷键就可以了?

Post by black1396 » 17 Feb 2017, 03:31

是运行失败,还是按快捷键的时候,执行失败(没有预期效果)?

感觉这一段里有个问题:
每次按Alt-1,都重新赋值active_id
WinGet, active_id, ID, A
...
那么后面的
IfWinNotActive, ahk_id %active_id%
这句理论上讲是永远为假的.

即是说,你按一次Alt-1标记了窗口1.
切到窗口2时,再按Alt-1,active_id就变成窗口2的了,这时如果激活了窗口1,反倒令人不解.

如何用autohotkey给当前窗口绑定一个快捷键,想要切换到这个窗口,只要按这个快捷键就可以了?

Post by willzheng7 » 09 Feb 2017, 15:21

我自己写了一段代码,确实可以实现这个功能。

但是想要给多个窗口绑定一个快捷键却失败了。 我想要用 “ALT+1” ,“ALT+2” ,“ALT+3” ,“ALT+4” ,分别绑定不同的窗口。 请问代码应该怎么写? 谢谢。 (上次在知乎提问,很顺利的得到了解决方案, 希望这次也有人可以帮助我。)

;以下是我自己写的代码,我尝试这个段代码复制4遍, 只修改其中的快捷键。 但是运行失败了。 不知道原因在哪里,谢谢指教。

;Open this windows with hotkey ALT + 1
!1::
WinGet, active_id, ID, A
MsgBox, You can activate this window with "ALT + 1"
Loop {
GetKeyState, stateA, ALT
GetKeyState, stateB, 1
if stateA = D
if stateB = D
{
IfWinNotActive, ahk_id %active_id%, , WinActivate, ahk_id %active_id%,
WinWaitActive, ahk_id %active_id%,
}

}
return

Top