Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.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 自动热键-输入热键组合-暂停一次按键-快捷键_Autohotkey - Fatal编程技术网

Autohotkey 自动热键-输入热键组合-暂停一次按键-快捷键

Autohotkey 自动热键-输入热键组合-暂停一次按键-快捷键,autohotkey,Autohotkey,我如何: 读取(等待并记录)单次按下(即Shift-Alt-F5) 将此录制的组合键传递给程序(即Photoshop),而不将其作为热键运行 我试过这个,但对我的非ASCII热键无效。它适用于t热键 F6:: Suspend, On Input, OutputVar, L1 M Send, %OutputVar% Suspend, Off return F5::Run explorer t::Run notepad !+5::Run cmd F5是运行程序资源管理器的热键 F6是一个热

我如何:

  • 读取(等待并记录)单次按下(即Shift-Alt-F5)
  • 将此录制的组合键传递给程序(即Photoshop),而不将其作为热键运行
  • 我试过这个,但对我的非ASCII热键无效。它适用于t热键

    F6::
    Suspend, On
    Input, OutputVar, L1 M
    Send, %OutputVar% 
    Suspend, Off
    return
    
    
    F5::Run explorer
    t::Run notepad
    !+5::Run cmd
    
    • F5是运行程序资源管理器的热键
    • F6是一个热键,按下一次可挂起所有热键。并作为非热键通过键组合
    • 当我在firefox中时,如果我按F6 F5,它将进入firefox的刷新页面操作
    • 当我按F5时,如果前面没有F6,它将打开资源管理器
    两种解决方案

  • 将要捕获的热键添加到输入中,如下所示:

    Input, OutputVar, L1, {LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{Capslock}{Numlock}{PrintScreen}{Pause}
    
  • 否则,这些非ascii键将被输入忽略

    或者,使F5键的行为特定于应用程序

    SetTitleMatchMode, 2
    #IfWinNotActive, Firefox
        F5::Run explorer
    #IfWinNotActive
    

    这样,您的F5键将始终启动IE,除非您在Firefox中工作,然后F5将是F5并重新加载您的页面。

    根据您的笔记,我认为您希望执行以下操作。 使用#r阻止任何输入并启动脚本,然后再次按#r时,脚本停止并恢复输入。在这种情况下,您可以尝试以下方法:

    #Singleinstance force
    $#r::
    If (MyToggle := !MyToggle) ; Toggle the value MyToggle True/False
        {
            ToolTip,Input  blocked [Win]+r,A_ScreenWidth/2-50,0
            BlockInput, on ; In Vista and above, you need to run AHK as admin or run AHK in compatility mode with Windows XP SP 3
            SetTimer RunMyScript, 500 ; Start the actual script in 500 ms outside of this script, so you can toggle
            Return
        }
    Else
        {
            Tooltip
            BlockInput, off
            ;Reload ; This will KILL the "RunMyScript" IMMEDIATELY at an unpredictable location.
            Return
        }
    return
    
    RunMyScript: ; This script runs independently from the script above. The script stops after 10 loops and resets the input. [Ctrl]+[Alt]+[Del] still kills any script.
    SetTimer RunMyScript, Off ; Turn the 500 ms timer off
    loop, 10
    {
        if (!MyToggle) ; Check the MyToggle variable to see if you need to stop the script. This will Exit the script at a predictable location.
            Exit
    
        SoundBeep, 600,600
        Sleep, 1000
    }
    BlockInput, off ; Allow keyboard & mouse input again. Warning the [Win] key key may be left activated, causing keyboard actions to start applications
    Tooltip
    Return
    

    让我知道这是否是您正在寻找的内容。

    通过这种方式可以将内容写入日志文件。在这里,我每天创建一个新的日志文件,对于每个条目,您必须返回最后两行(以获取实际时间)


    我还没有检查这个,但我想这就是你要找的

    FormatTime, DateRef, %TimeNow%, yyyyMMdd ; Store current date in variable DateRef
    MyLogFile = %A_ScriptDir%\LogFiles\LogFile-%DateRef%.txt ; Define the name of the log file.
    FileAppend, `n`r| %TimeAbsolute% | Your hotkey and possibly in which application`n`r,%MyLogFile% ; Write logfile
    Suspend, on ; Start with hotkeys disabled
    Return
    
    Pause:: ; Use pause key to 'activate' the hotkeys
    Suspend, Off ; Activate the hotkeys
    SetTimer, Stop, 10000 ; If no hotkey is pressed within 10 seconds, deactivate the hotkeys aagain
    Return
    
    Stop: ; Deactivate the hotkeys
    Suspend, on ; Deactivate the hotkeys
    SetTimer, Stop, Off ; turn the stop timer off
    Return
    
    q:: ; use a key (q) as a hotkey
    Soundbeep, 600,600 ; sound a short beep to show that it works
    HotKeyType = "q key"
    WinGet, ApplicationType, ProcessName, A
    GoSub, Write
    Return
    
    Write:
    SetTimer, Stop, Off ; Make sure that the stop timer is turned off
    FormatTime, TimeAbsolute, %TimeNow%, HH:mm:ss ; Use the current time to set  the timestamp variable called TimeAbsolute used inside the Log File
    FileAppend, `n`r| %TimeAbsolute% | %HotKeyType% used in %ApplicationType%`n`r,%MyLogFile% ; Write logfile
    Suspend, On ; Disable the hotkeys again
    Exit
    

    关于记录键,我专门将要在日志文件中打印的键类型定义为文本字符串,这样您就可以为每个不可打印的键定义自己的文本

    我按照以下方式重新编写了脚本: 当您按F6一次,然后再按另一个键(在本例中为F5)时,它将发出嘟嘟声(充当热键)。如果按F6两次,If将发送F6,就像未设置热键一样。如果不先按F6而按F5,它将只发送F5,就像没有热键处于活动状态一样。希望这就是你想要的

    $F6::
    If (MySuspend := !MySuspend) ; Toggle the value MySuspend True/False
    {
            ToolTip Hotkeys On (F6),A_ScreenWidth/2-50,0
    }
    Else
    {
        Tooltip
        Send, {F6}
    }
    return
    
    $F5::
    If MySuspend
    {
        SoundBeep, 600, 600
        MySuspend := 0
        ToolTip
    }
    else
    {
        Send, {F5}
    }
    Return
    

    好吧,我想这是最后的剧本了

    正常情况下,除非按F6键,否则所有键都会正常工作,然后在3秒钟内可以使用热键。一旦您使用热键,行为将再次恢复正常(只有在您未按下热键的情况下,才会出现3秒钟)。当您按F6两次时,它将发送F6。让我知道你是否找到了一个更简单的解决方案,因为这是相对复杂的

    FormatTime, DateRef, %TimeNow%, yyyyMMdd ; Store current date in variable DateRef
    MyLogFile = %A_ScriptDir%\LogFile-%DateRef%.txt ; Define the name of the log file for today.
    FormatTime, TimeAbsolute, %TimeNow%, HH:mm:ss
    FileAppend, | %TimeAbsolute% | Your hotkey and possibly in which application`n`r,%MyLogFile% ; Write logfile
    SpecialF6:=1
    Suspend, On
    Return
    
    $F6::
    Suspend, Permit
    If SpecialF6
    {
    Suspend, Off
    ToolTip Hotkeys On for 3 seconds,A_ScreenWidth/2-50,0
    SpecialF6:=0
    SetTimer, SuspendOn, 3000
    Return
    }
    else
    {
        Send, {F6}
        MyText = F6
        Gosub, WriteClose
    }
    Return
    
    SuspendOn:
    Suspend, On
    SetTimer, SuspendOn, Off
    ToolTip
    SpecialF6:=1
    return
    
    F5::
    Run explorer
    MyText = F5 Run Explorer
    Gosub, WriteClose
    Return
    
    t::
    Run notepad
    MyText = t Run Notepad
    Gosub, WriteClose
    Return
    
    !+5::
    Run cmd
    MyText = Alt Shift 5 Run Command
    Gosub, WriteClose
    return
    
    WriteClose:
    Suspend, On
    SetTimer, SuspendOn, Off
    FormatTime, TimeAbsolute, %TimeNow%, HH:mm:ss
    ToolTip
    SpecialF6:=1
    FileAppend, | %TimeAbsolute% | %MyText%`n`r,%MyLogFile% ; Write logfile
    Exit
    

    谢谢这回答了问题,但我用词不对。。。我希望能够录制单个热键(可能)组合按键(即#r)。。。我认为您的解决方案只记录了一次按键(仅记录了#in#r)。。。我的例子是虚构的。。。。我希望能够按下一个热键,然后它只需按下一个热键组合键(即#r)就可以暂停脚本,传递这些键,然后切换暂停的脚本。我仍然不清楚您的真正目标。请尽量做到具体,不要捏造事实。从我读到的内容来看,我认为您需要以下内容:按热键(#r)启动脚本。当脚本运行时,任何击键都应该做什么?然后当你再次点击(#r)时,停止脚本?你说的是通过“钥匙”。你这么说是什么意思?可以将Suspend映射到一个键,以便轻松地打开和关闭热键绑定。。。。我想在一个键上关闭键绑定,然后按下一个热键绑定,该热键绑定掩盖了程序的默认行为,让它启动程序的默认行为,然后直接打开热键绑定,而不必按另一个键。另外,我想将按下的键绑定记录到一个文件中。让我试着写回我读到的内容。在Ahk中,您定义了几个热键,但不希望在正常条件下激活这些热键。如果您按下一个特殊的激活热键,那么您希望其他热键被激活,但一旦您按下(并执行)一个热键,Ahk的行为应返回到初始阶段,在该阶段,热键(用于激活其他热键的热键除外)再次关闭,因此您可以将这些热键用于其“本机”功能。使用Ahk pause功能可以最好地描述(模拟)您正在寻找的行为,即您在暂停模式下以Ahk开始(即热键不起作用),然后取消暂停或激活一个热键的Ahk(热键处于活动状态),按下此热键后,让Ahk再次返回暂停模式。你能证实这一行为吗(我不是说这是解决方案,我首先试图弄清楚你在寻找什么样的行为)。谢谢你的所有努力。。。我在记录到文件时遇到的问题是,记录的密钥并不总是人类可读的形式。有时它是一个符号,而不是类似于“CTRL F5”的东西。我注意到您向日志文件发送了按键的字符串表示形式。但您并没有监听任何要按下的键,而是将其映射到一个热键,并知道按下了哪些键来调用该特定实例。这个解决方案的扩展性非常差,维护和编写都很困难。上面的解决方案是一个可以调整的黑客程序,可以用来解决这个问题。但是,它不允许我在没有映射到自动热键的按键上阅读和操作(这只是调试时真正需要的)。这也是一种糟糕的编码实践。。。。我希望能够等待按下任何键(即Ctrl+y),然后执行操作。正在按下的键可能与自动热键相关联,也可能与自动热键不相关。我正在尝试提供帮助,但我注意到您一直在更改范围。当然,若您想捕获所有密钥,此解决方案不会扩展。您的请求只提到了3个热键,没有提到调试的用途。与其使用input命令捕获键(由于各种可能的修饰符,其长度不确定),不如
    FormatTime, DateRef, %TimeNow%, yyyyMMdd ; Store current date in variable DateRef
    MyLogFile = %A_ScriptDir%\LogFile-%DateRef%.txt ; Define the name of the log file for today.
    FormatTime, TimeAbsolute, %TimeNow%, HH:mm:ss
    FileAppend, | %TimeAbsolute% | Your hotkey and possibly in which application`n`r,%MyLogFile% ; Write logfile
    SpecialF6:=1
    Suspend, On
    Return
    
    $F6::
    Suspend, Permit
    If SpecialF6
    {
    Suspend, Off
    ToolTip Hotkeys On for 3 seconds,A_ScreenWidth/2-50,0
    SpecialF6:=0
    SetTimer, SuspendOn, 3000
    Return
    }
    else
    {
        Send, {F6}
        MyText = F6
        Gosub, WriteClose
    }
    Return
    
    SuspendOn:
    Suspend, On
    SetTimer, SuspendOn, Off
    ToolTip
    SpecialF6:=1
    return
    
    F5::
    Run explorer
    MyText = F5 Run Explorer
    Gosub, WriteClose
    Return
    
    t::
    Run notepad
    MyText = t Run Notepad
    Gosub, WriteClose
    Return
    
    !+5::
    Run cmd
    MyText = Alt Shift 5 Run Command
    Gosub, WriteClose
    return
    
    WriteClose:
    Suspend, On
    SetTimer, SuspendOn, Off
    FormatTime, TimeAbsolute, %TimeNow%, HH:mm:ss
    ToolTip
    SpecialF6:=1
    FileAppend, | %TimeAbsolute% | %MyText%`n`r,%MyLogFile% ; Write logfile
    Exit