GetKeyState - possible bug

Issue #101 closed
Winter Laite created an issue

It may be just incorrect syntax - Keysharp crashes when the created hotkey combo (Space + f & j) is triggered. Syntax differences from the AHK code from which it was ported are significant (partly due to the four lambdas in the AHK code), thus my uncertainty as to whether the code is ostensibly correct.

Keysharp code:

Saved := ""

HkGui := Gui()
HkGui.Add("Text", "xm", "Prefix key:")
HkGui.Add("Edit", "yp x100 w100 vPrefix", "Space")
HkGui.Add("Text", "xm", "Suffix hotkey:")
HkGui.Add("Edit", "yp x100 w100 vSuffix", "f & j")
HkGui.Add("Button", "Default", "Register").OnEvent("Click", "RegisterHotkey")
HkGui.OnEvent("Close", "LeaveNow")
HkGui.OnEvent("Escape", "LeaveNow")
HkGui.Show()

RegisterHotkey()
{
    Saved := HkGui.Submit(false)
    HotIf("func1")
    Hotkey(Saved["Suffix"], "func2")
    ;MsgBox(Saved["Suffix"])
}

LeaveNow() {
    ExitApp()
}

func1() {
    global
    GetKeyState(Saved["Prefix"], "A")
}

func2(ThisHotkey)
{
    MsgBox(ThisHotkey)
}

Working AHK code:

HkGui := Gui()
HkGui.Add("Text", "xm", "Prefix key:")
HkGui.Add("Edit", "yp x100 w100 vPrefix", "Space")
HkGui.Add("Text", "xm", "Suffix hotkey:")
HkGui.Add("Edit", "yp x100 w100 vSuffix", "f & j")
HkGui.Add("Button", "Default", "Register").OnEvent("Click", RegisterHotkey)
HkGui.OnEvent("Close", (*) => ExitApp())
HkGui.OnEvent("Escape", (*) => ExitApp())
HkGui.Show()

RegisterHotkey(*)
{
    Saved := HkGui.Submit(false)
    HotIf (*) => GetKeyState(Saved.Prefix)
    Hotkey Saved.Suffix, (ThisHotkey) => MsgBox(ThisHotkey)
}

Comments (2)

  1. Log in to comment