InputHook - present in Keysharp.Core.Input, but isn't working

Issue #56 closed
Winter Laite created an issue

InputHook docs page.

InputHook is more flexible than using hotstrings, but harder to use.

This code throws a Keyview error:

MsgBox KeyWaitAny("V")

KeyWaitAny(Options:="")
{
    ih := InputHook(Options)
    if !InStr(Options, "V")
        ih.VisibleNonText := false
    ih.KeyOpt("{All}", "E")  ; End
    ih.Start()
    ih.Wait()
    return ih.EndKey  ; Return the key name
}

The following errors occurred:Keyview:: (107,8)-(107,17) - The name 'InputHook' does not exist in the current context

An example of InputHook’s flexibility can be found on the Switch docs page. (I was testing ‘Switch’ when I found this issue.)

Comments (7)

  1. Matt Feemster repo owner

    I’ve committed a fix, please test.

    Here is a reworked version of the third example at the bottom of the AHK documentation page:

    https://lexikos.github.io/v2/docs/commands/InputHook.htm

    #persistent
    WordList := "Monday`nTuesday`nWednesday`nThursday`nFriday`nSaturday`nSunday"
    Suffix := ""
    SacHook := InputHook("V", "{Esc}")
    
    SacHook.OnChar := "SacChar"
    SacHook.OnKeyDown := "SacKeyDown"
    SacHook.KeyOpt("{Backspace}", "N")
    SacHook.Start()
    
    SacChar(ih, char)  ; Called when a character is added to SacHook.Input.
    {
        global WordList, Suffix := ""
        temp := ""
        prefix := ""
    
        if ((prefix := RegExMatch(ih.Input, "`nm)\w+$")) && (temp := RegExMatch(WordList, "`nmi)(?<=^" . prefix[0] . ").*")))
        {
            Suffix := temp[0]
        }
    
        cp := CaretGetPos()
    
        if (cp["CaretFound"])
            ToolTip(Suffix, cp["X"] + 15, cp["Y"])
        else
            ToolTip(Suffix)
    
        ; Intercept Tab only while we're showing a tooltip.
        ih.KeyOpt("{Tab}", Suffix = "" ? "-NS" : "+NS")
    }
    
    SacKeyDown(ih, vk, sc)
    {
        if (vk == 8) ; Backspace
            SacChar(ih, "")
        else if (vk == 9) ; Tab
            Send("{Text}" Suffix)
    }
    

  2. Log in to comment