【问题标题】:How to suspend an ahk script when another programm (eg. Microsoft Edge) is open?当另一个程序(例如 Microsoft Edge)打开时,如何暂停 ahk 脚本?
【发布时间】:2021-10-25 02:33:18
【问题描述】:

我是个编程菜鸟,所以请多多包涵。所以我想要的是能够在 chrome 中快速搜索选定的文本,除非 Microsoft Edge 浏览器打开,在这种情况下脚本应该被暂停。此外,如果脚本被暂停 ^+e 应该像往常一样通过 Cntrl + Shift + E 。这是我走了多远:

^+e:: 
Send, ^c
Sleep, 100
Run, www.google.com
Sleep, 100
Send, ^v
Send, {Enter}
Sleep, 300
Send, ^v
Send, {Enter}
Sleep, 300
Send, ^v
Send, {Enter}
Sleep, 300
Send, ^v
Send, {Enter}
Sleep, 300
Send, ^v
Send, {Enter}
Sleep, 300
Send, ^v
Send, {Enter}
return


IfWinActive,  Microsoft Edge
  {
     Suspend, on
  }
  else
  {
     Suspend, off
  }
return

我真的不确定 IfwinActive 行。谢谢你的帮助。

【问题讨论】:

    标签: autohotkey


    【解决方案1】:

    为此设计了上下文相关的热键。
    对于这种特定情况,#IfWinNotActive(docs) 指令很好。
    有了它,您可以将所需的热键标记为不在某些特定窗口下。

    #IfWinNotActive, ahk_exe msedge.exe ;start context sensitive hotkeys
    ^+e::
        MsgBox, % "Do something"
        ;...
    return
    
    +F1::
        MsgBox, % "Do something"
        ;...
    return
    #IfWinNotActive ;end context sensitive hotkeys
    

    另外,我真的不知道你在做什么这个 ctrl + v 垃圾邮件,但是要搜索一些东西,也许可以考虑运行类似的东西这个:

    TextToSearch := "stackoverflow autohotkey questions"
    Run, % "chrome.exe ""https://www.google.com/search?q=" TextToSearch """" 
    

    您可以通过Clipboard(docs)访问系统剪贴板。

    【讨论】:

    • 但是当我输入这样的代码时,当 Microsoft Edge 打开时,该命令仍然执行:^+e:: Send, ^c Sleep, 50 Run, www.google.com Sleep, 100 Send, ^v Send, {Enter} Sleep, 300 Send, ^v Send, {Enter} Sleep, 300 Send, ^v Send, {Enter} Sleep, 300 Send, ^v Send, {Enter} Sleep, 300 Send, ^v Send, {Enter} return #IfWinNotActive, ahk_exe ahk_exe msedge.exe ^+e:: MsgBox, % "Do something" return +F1:: MsgBox, % "Do something" #IfWinNotActive
    • @LeonFasser #IfWinNotActive 只影响它所在行之后的代码。另外,为了将来参考,请使用 pastebin 在评论中转储长的多行代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-26
    • 1970-01-01
    • 2017-01-30
    • 2018-09-19
    • 2017-02-09
    • 1970-01-01
    相关资源
    最近更新 更多