为什么在运行此脚本时抑制空格键事件?

时间:2019-07-01 22:08:44

标签: autohotkey detection space

我制作了一个脚本,使用dvorak键盘布局在Windows 10中用左手平铺窗口。它可以按预期工作,除了它可以使空格键事件不会进入脚本本身以外的任何程序。这是运行脚本时的键盘日志:

07/01 19:35:39: Launching app
$ adb shell am start -n "com.gnd.keepkey / com.gnd.keepkey.Telephone" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Client not ready yet..Waiting for process to come online
Waiting for process to come online
Connected to process 27724 on device motorola-moto_z2_play-0039635857
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I / zygote: Do partial code cache collection, code = 20KB, data = 29KB
I / zygote: After code cache collection, code = 20KB, data = 29KB
    Increasing code cache capacity to 128KB
I / zygote: Do partial code cache collection, code = 20KB, data = 47KB
I / zygote: After code cache collection, code = 20KB, data = 47KB
    Increasing code cache capacity to 256KB
I / zygote: Compiler allocated 4MB to compile void android.widget.TextView. <Init> (android.content.Context, android.util.AttributeSet, int, int)
I / zygote: Full code cache collection, code = 120KB, data = 82KB
I / zygote: After code cache collection, code = 117KB, data = 62KB
I / zygote: Do partial code cache collection, code = 125KB, date = 79KB
I / zygote: After code cache collection, code = 125KB, data = 79KB
    Increasing code cache capacity to 512KB
W / System.err: java.io.FileNotFoundException: /storage/emulated/0/teste/dados.db (No such file or directory)
        at java.io.FileOutputStream.open0 (Native Method)
W / System.err: at java.io.FileOutputStream.open (FileOutputStream.java:287)
        at java.io.FileOutputStream. <init> (FileOutputStream.java:223)
        at java.io.FileOutputStream. <init> (FileOutputStream.java:110)
        at com.gnd.keepkey.funcoes.Exportar_Importar.backupDatabase (Export_Importar.java:87)
        at com.gnd.keepkey.funcoes.Exportar_Importar.access $ 000 (Export_Importar.java:42)
        at com.gnd.keepkey.funcoes.Export_Import $ 1.onClick (Export_Import.java:69)
W / System.err: at android.view.View.performClick (View.java:6259)
        at android.view.View $ PerformClick.run (View.java:24732)
        at android.os.Handler.handleCallback (Handler.java:789)
        at android.os.Handler.dispatchMessage (Handler.java:98)
        at android.os.Looper.loop (Looper.java:164)
        at android.app.ActivityThread.main (ActivityThread.java:6592)
        at java.lang.reflect.Method.invoke (Native Method)
W / System.err: at com.android.internal.os.Zygote $ MethodAndArgsCaller.run (Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:769)

两个空间事件均被正确检测,但仍被抑制。手动终止脚本可以解决此问题。

20  039 s   d   0.09    Space           
20  039 s   u   0.08    Space           
20  039 s   d   0.08    Space           
20  039 s   u   0.08    Space           
20  039 s   d   0.08    Space           
20  039 s   u   0.09    Space           
20  039 s   d   0.08    Space           
20  039 s   u   0.09    Space           
20  039 s   d   31.14   Space           
20  039 s   u   0.11    Space           
20  039 s   d   0.09    Space           
20  039 s   u   0.11    Space

PS,我用了空间,因为我的左Windows键已物理损坏。 将Space绑定到自身,然后添加“ Space :: Space”行,部分起作用,只有up事件被注册为热键,因此它仅在释放空格键时才触发,从而产生以下结果:

  #MaxThreads 255 ; for the purpose of troubleshooting

    #e::return      
    #.::return 
    #o::return          
    #u::return       

    Space & u::  
    Space & .::
    Space & o::
    Space & e::
    send {LWin Down}
    spcup()       
    exit

    spcup()                                                                          
    {
    while GetKeyState("Space", "P") {
    rite := GetKeyState("u", "P")
    left := GetKeyState("o", "P")
    up := GetKeyState(".", "P") 
    down := GetKeyState("e", "P")           
    if (rite=1) {
        Sleep 75
        Send {Right}
        Sleep 75
        }
        else if (left=1) {
            Sleep 75
            Send {Left}
            Sleep 75 
            }   
        else if (up=1) {
            Sleep 75
            Send {Up}
            Sleep 75  
            }
        else if (down=1) {
            Sleep 75
            Send {Down}
            Sleep 75
            }
        else if !GetKeyState("Space", "P") { 
            sleep 75
            Send {LWinUp}
            exit
            }
    }
    }

“已解决”,有点。没有〜,前缀键无法保持其原始功能,因此会将其发送到活动窗口,这是不必要的。

20  039 s   d   0.25    Space           
20  039 h   u   0.16    Space           
20  039 i   d   0.00    Space           
20  039 i   u   0.00    Space   

s=suppressed
h=hotkey
i=ignored(sent by autohotkey itself)

1 个答案:

答案 0 :(得分:1)

来自help documentation

Numpad0 & Numpad1::MsgBox You pressed Numpad1 while holding down Numpad0.
Numpad0 & Numpad2::Run Notepad
     

前缀键失去其本机功能:在上面的示例中,   Numpad0成为前缀键;但这也会导致Numpad0失去其   本身按下时的原始/本机功能。为了避免这种情况,   脚本可以将Numpad0配置为执行新操作,例如   以下:

Numpad0::WinMaximize A   ; Maximize the active/foreground window.
Numpad0::Send {Numpad0}  ; Make the release of Numpad0 produce a
Numpad0 keystroke. See comment below.
     

发布时触发:存在上述自定义组合之一   热键使Numpad0的 release 执行指示的操作,   但前提是您在进行Numpad0时未按任何其他键   按住。 [v1.1.14 +]:可以通过应用   任一热键的代字号前缀。

在每个~热键上添加波浪号前缀Space &可以使其表现出预期的效果。或者,您可以添加~Space::Return

请注意,这将始终发送一个空格,这可能在不同的应用程序中产生意想不到的后果。例如,在浏览器中,它将向下滚动,类似于按 向下翻页键。

这是我用于测试的代码的精简版本:

~Space & u::
~Space & .::
~Space & o::
~Space & e::
aReplace := [[ "u" , "Right" ] , [ "o" , "Left" ] , [ "." , "Up" ] , [ "e" , "Down" ]]
Loop , % aReplace.Length()
    sReplace := ( SubStr( A_ThisHotkey , 0 , 1 ) = aReplace[ A_Index , 1 ] ) ? aReplace[ A_Index , 2 ] : sReplace
Send , #{%sReplace%}
Return