Autohotkey - 用于热键组合的输入 - 暂停一个按键 - 通过键

时间:2012-07-16 19:02:18

标签: autohotkey

我如何:

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

    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时,它将打开资源管理器

6 个答案:

答案 0 :(得分:1)

两种解决方案。

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

    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}
    
  2. 否则输入会忽略这些非ascii键。

    或者,使F5密钥应用程序的行为特定。

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

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

答案 1 :(得分:1)

根据您的说明,我认为您要执行以下操作。 使用#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

如果您正在寻找,请告诉我。

答案 2 :(得分:0)

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

FormatTime, DateRef, %TimeNow%, yyyyMMdd ; Store current date in variable DateRef
MyLogFile = %A_ScriptDir%\LogFiles\LogFile-%DateRef%.txt ; Define the name of the log file.
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% | Your hotkey and possibly in which application`n`r,%MyLogFile% ; Write logfile

答案 3 :(得分:0)

我还没有检查过这个,但我认为这就是你要找的......

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

答案 4 :(得分:0)

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

我用以下方式重写了脚本: 当您按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

答案 5 :(得分:0)

好吧我觉得这是最后的剧本......

通常所有按键都按照常规操作,除非您按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