Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Autohotkey 用于在Windows 10上激活始终位于顶部的计算器的AHK脚本_Autohotkey - Fatal编程技术网

Autohotkey 用于在Windows 10上激活始终位于顶部的计算器的AHK脚本

Autohotkey 用于在Windows 10上激活始终位于顶部的计算器的AHK脚本,autohotkey,Autohotkey,如何使用AHK激活始终处于顶部模式的Windows10计算器应用程序 当计算器处于标准模式时,若你们点击“保持在顶部”,它会变成这样 请注意,它没有标题栏 我用来激活已经打开的计算器的AHK脚本不再工作 #c:: if not WinExist("Calculator") { Run calc.exe WinWait Calculator } WinActivate Calculator 我尝试了的技巧 但我

如何使用AHK激活始终处于顶部模式的Windows10计算器应用程序
当计算器处于标准模式时,若你们点击“保持在顶部”,它会变成这样

请注意,它没有标题栏
我用来激活已经打开的计算器的AHK脚本不再工作

#c::
    if not WinExist("Calculator")
    {
        Run calc.exe
        WinWait Calculator
    }
    WinActivate Calculator
我尝试了
的技巧 但我没有得到有效的类id,这是我的脚本,添加了一些调试:

#c::
    DetectHiddenWindows, on

    Process, Exist, Calculator.exe
    cpid := ErrorLevel    
    WinGetClass, ClassID, ahk_pid %cpid%
    WinGetTitle, Title, ahk_pid %cpid%
    exist := WinExist("ahk_exe Calculator.exe")
    active := WinActive("ahk_exe Calculator.exe")
    MsgBox look for [%cpid%] [%Title%] [%ClassID%] [%exist%] [%active%] ; cpid is the only valid variable

    if not WinExist("Calculator")
    {
        Run calc.exe
        WinWait Calculator
    }

    WinActivate Calculator

修改您现有的脚本(您不需要通过获取PID和ahk_类来过度复杂)


该窗口不是来自
Calculator.exe
,而是来自
ApplicationFrameHost.exe

而且它不会是来自该可执行文件的唯一窗口。因此,我建议先存储计算器窗口,然后再使用它

#!c::
#c::
    Process, Exist, % "Calculator.exe"  ;see if a calculator exists
    if (!ErrorLevel)                    ;ErrorLevel was set to 0 (false) if doesnt exist
    {
        Run, % "calc.exe"
        WinWait, % "Calculator"         ;make sure this is correct for your language
        hwnd := WinExist()              ;use last found window
        return
    }
    else if (!hwnd || A_ThisHotkey ~= "!") ;set or update hwnd      
        hwnd := WinActive("A")
    else
        WinActivate, % "ahk_id " hwnd
return
因此,一个两个热键的解决方案,另一个热键只是额外的,它甚至不需要,除非您关闭并重新启动计算器,并且需要重新获取其hwnd。
首先,我们检查计算器是否存在,如果不存在,则启动一个,等待它打开,存储其hwnd并返回。
有用的文档链接:和

如果确实存在计算器,请检查是否存储了hwnd,或者是否使用了可选热键Win+Alt+C。
如果您打开了一个计算器,但没有存储它的hwnd,则会出现这种情况。您可以手动激活计算器窗口并存储其hwnd。
有用的文档链接:和Regex匹配速记(检查
中是否有
找到此热键)


最后,如果没有什么特别需要做的,并且只使用了基本的Win+C热键,只需激活计算器。

我认为问题主要在于,如果他使用从按钮启动的紧凑型计算器,这个检查
WinExist(“计算器”)
将无法工作。这个问题在这个脚本中仍然存在。有趣的是。。。Window Spy告诉我,最上面的版本确实有一个窗口标题“Calculator”,但您的陈述是正确的,
WinExist(“Calculator”)
不能正常工作@0x464eIt有效,谢谢。我想了解为什么
WinGet
带有
ahk_id
ahk_exe
失败。我甚至试着在所有窗口中循环:
WinGet、id、List、、程序管理器循环、%id%…
#!c::
#c::
    Process, Exist, % "Calculator.exe"  ;see if a calculator exists
    if (!ErrorLevel)                    ;ErrorLevel was set to 0 (false) if doesnt exist
    {
        Run, % "calc.exe"
        WinWait, % "Calculator"         ;make sure this is correct for your language
        hwnd := WinExist()              ;use last found window
        return
    }
    else if (!hwnd || A_ThisHotkey ~= "!") ;set or update hwnd      
        hwnd := WinActive("A")
    else
        WinActivate, % "ahk_id " hwnd
return