【问题标题】:How to make, in AutoHotkey, a code where all programs which are opened receive a certain Hotkey?如何在 AutoHotkey 中制作一个代码,所有打开的程序都接收某个热键?
【发布时间】:2021-12-24 06:44:47
【问题描述】:

我是 Autohotkey 的新手,我发现它很吸引人,我想知道我是否可以用它来做我寻找了几个月的事情:一旦你打开一个程序,它会自动接收普通程序的热键 F11 (无例外)和 UWP 应用的热键 Shift + Win + Enter。

目标始终是在全屏、普通程序或 UWP 应用中打开程序。只有当您立即打开程序时,才会执行此代码。如果程序没有全屏模式功能,它就不会工作,这很好。

有人可以帮我吗?非常感谢。

【问题讨论】:

    标签: automation autohotkey


    【解决方案1】:

    您需要一个timer 来使用WinGet 命令获取所有窗口的列表,以便检测新窗口:

    #NoEnv
    #SingleInstance Force
    
    #Persistent
    
    WinList()
    
    SetTimer, FullScreen, 300
    Return 
    
    FullScreen:
        active_id := "" 
        WinGet, active_id, ID, A
        If !InStr(wins, active_id)
        {
            SetTimer, FullScreen, off
            WinGetClass, ActiveClass, ahk_id %active_id%
            If (ActiveClass="ApplicationFrameWindow")
                SendInput, +#{Enter}
            else
                SendInput, {F11}
            WinList()
            WinWaitNotActive, ahk_id %active_id%
            SetTimer, FullScreen, on
        }
    Return
    
    WinList(){
        global
        list := ""
        wins := ""
        WinGet, id, list,,, Program Manager
        Loop, %id%
        {
            this_ID := id%A_Index%
            WinGetTitle, title, ahk_id %this_ID%
            If (title = "")
                continue    
            WinGetClass, class, ahk_id %this_ID%
            If (class = "")
                continue
            WinGet, Style, Style, ahk_id %this_ID%
            if !(Style & 0x10000000)    ; WS_VISIBLE
            {
                WinGet, ExStyle, ExStyle, ahk_id %this_ID%
                If (this_ID != "0x00000180") 
                    continue
            }
            wins .= this_ID ? this_ID "`n" : ""
            wins := Trim(wins)
        }
    }
    

    编辑:

    Shell Hook 为您提供更好的服务:

    #NoEnv
    #SingleInstance Force
    
    Gui +LastFound
    hWnd := WinExist()
    DllCall("RegisterShellHookWindow", UInt,WinExist())
    MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
    OnMessage( MsgNum, "ShellMessage" )
    return
    
    ShellMessage( wParam,lParam )
    {
        WinGet, pname, ProcessName, ahk_id %lParam%
        WinGetTitle, title_W, ahk_id %lParam%
        WinGetClass, class_W, ahk_id %lParam%
        If ((title_W != "") && (class_W != ""))
        {
            If ( wParam = 1 ) ; 1 means HSHELL_WINDOWCREATED
            {
                If (class_W != "Windows.UI.Core.CoreWindow") 
                    SendInput, {F11}
            }
            else
            If ( wParam = 2 ) ;  2 means HSHELL_WINDOWDESTROYED
            {
                    If (class_W = "Windows.UI.Core.CoreWindow")
                    {
                        If WinActive(title_W "ahk_class ApplicationFrameWindow") 
                            SendInput, +#{Enter}
                    }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-14
      • 2021-06-28
      • 1970-01-01
      • 2016-02-28
      • 2016-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多