2012-07-16 323 views
1

如何:AutoHotkey的 - 热键组合输入 - 暂停一个按键 - 通电路关键

  1. 读(等待和记录),只需按一下(即按住Shift键的Alt-F5)
  2. 通过这记录关键组合到程序(即Photoshop),没有它作为热键运行。

我试过这个,但它不适用于我的非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,它会打开资源管理器
+0

而是与输入命令捕获键(未定长度由于各种可能的调节剂),也许你可以触发类似WM_KEYUP。对于每个按下的键,追踪每个按下的键(修饰键)。不断监测最后按下的按键,看看它是否被释放。按住最后一个按键的这个按钮就是你按下热键的触发器,并触发继续脚本。 – 2012-07-29 10:45:31

+0

B.t.w.你能否展示你在同一时间做了什么来尝试解决这个问题? – 2012-07-29 10:47:53

+0

我一直在寻找帮助,网络和查看关键记录器脚本......我看不到一个干净的解决方案......我将坚持有一个热键来切换所有热键的暂停(除了切换热键热键),然后当我将超过阴影的按键传递给底层程序时重新开启....我希望能够保存自己在按下热键后再按下按钮。我在linux窗口管理器中使用了函数quote-event来实现这个功能...感谢所有的帮助Robert – dericbytes 2012-07-30 09:37:50

回答

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} 
    

否则这些非ASCII键由输入忽略。

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

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

这样,你的F5键总是启动IE浏览器,当你的Firefox除了工作,然后F5F5并重新加载页面。

+0

谢谢......这回答了这个问题,但我说错了......我想能够记录一个热键(也许)COMBO按(即#r)...我认为你的解决方案只记录一个按键(只#在#中#)...我的例子是由......我想要为了能够按热键,然后让它暂停一个热键组合按(即#r)脚本,将这些键传递,然后切换挂起的脚本。 – dericbytes 2012-07-20 00:46:42

+0

你的真实目标仍然不清楚。请尽量做一个具体的,不要弥补的东西。从我阅读的内容来看,我认为您需要以下内容:按热键(#r)启动脚本。在脚本运行时应该用什么击键来完成?那么当你再次点击(#r)时,请停止脚本?你谈论通过“the”键。你是什​​么意思? – 2012-07-25 08:08:08

+0

可以将Suspend映射到一个键,以便轻松切换热键绑定....我想在一个键上切换键绑定,然后按热键绑定,掩盖了程序的默认行为,让它启动程序的默认行为然后立即回到我的热键绑定上,而不必按另一个键。另外,我想登录到键盘按下的文件。 – dericbytes 2012-07-27 09:08:55

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 

让我知道这是你在找什么。

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 
+0

感谢您的所有努力......我记录到文件的问题是被记录的密钥并不总是以人类可读的形式存在。有时它是一个符号,而不是像'CTRL F5' – dericbytes 2012-07-28 14:36:08

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 
0

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

我按照以下方式重新编写了脚本: 当您按F6一次,然后按另一个键(在此情况下为F5)时,它将执行哔声(充当热键)。如果按F6两次,如果将发送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 
+0

我注意到你发送了一个字符串表示的按键到日志文件。但是你并没有听取要按下的任何键,而是将它映射到一个热键,并知道哪些键已被按下来调用该特定实例。这个解决方案非常糟糕,并且很难维护和编写。 – dericbytes 2012-07-28 23:44:20

+0

上面的解决方案是可以调整来解决问题的黑客。但是,它不允许我在未映射到自动热键的按键上进行阅读和操作(这只是真正需要调试)。此外,这是不好的编码习惯....我想能够等待任何按键被按下(即Ctrl + Y),然后对它进行操作。被按下的键可能或不可以链接到自动热键。 – dericbytes 2012-07-28 23:58:08

+0

我正在尝试帮助,但我注意到您不断更改范围。当然,如果你想捕获所有的密钥,这个解决方案不会扩展。你的请求只提到了3个热键,并没有提到用于调试。 – 2012-07-29 10:58:22

0

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

通常所有的按键时3秒,除非您按F6的行为像往常一样,那么你可以使用热键。只要你使用热键,行为就会再次恢复正常(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