ControlSetEnabled() not working properly (only Toggle works)

Issue #92 closed
Winter Laite created an issue

Test AHK script (working):

MyGui := Gui(, "Enable Control")

BtnVictim := MyGui.Add("Button", "x10 y10", "Run monkey run")
BtnVictim.OnEvent("Click", RunMonkeyRun)

EnBtn1 := MyGui.Add("Button", "x10 y+10 w80", "Disable")
EnBtn1.OnEvent("Click", Enabled)

EnBtn2 := MyGui.Add("Button", "x10 y+10 w80", "Enable")
EnBtn2.OnEvent("Click", Disabled)

EnBtn3 := MyGui.Add("Button", "x10 y+10 w80", "Toggle")
EnBtn3.OnEvent("Click", Toggled)

MyGui.Show("w200 h200")

Enabled(*) {
    SetControlDelay -1
    ControlSetEnabled(0, BtnVictim, "Enable Control")
}

Disabled(*) {
    SetControlDelay -1
    ControlSetEnabled(1, BtnVictim, "Enable Control")
}

Toggled(*) {
    SetControlDelay -1
    ControlSetEnabled(-1, BtnVictim, "Enable Control")
}

RunMonkeyRun(*) {
    MsgBox("Help me find a banana!", "Support hungry primates")
}

Non-working Keysharp script (no errors thrown) - toggle works, but Enable and Disable (1/0, True/False) do not.

MyGui := Gui(, "Enable Control")

BtnVictim := MyGui.Add("Button", "x10 y10", "Run monkey run")
BtnVictim.OnEvent("Click", "RunMonkeyRun")

EnBtn1 := MyGui.Add("Button", "x10 y+10 w80", "Disable")
EnBtn1.OnEvent("Click", "Enabled")

EnBtn2 := MyGui.Add("Button", "x10 y+10 w80", "Enable")
EnBtn2.OnEvent("Click", "Disabled")

EnBtn3 := MyGui.Add("Button", "x10 y+10 w80", "Toggle")
EnBtn3.OnEvent("Click", "Toggled")

MyGui.Show("w200 h400")

Enabled() {
    SetControlDelay(-1)
    ControlSetEnabled(1, BtnVictim, "Enable Control")
}

Disabled() {
    SetControlDelay(-1)
    ControlSetEnabled(0, BtnVictim, "Enable Control")
}

Toggled() {
    SetControlDelay(-1)
    ControlSetEnabled(-1, BtnVictim, "Enable Control")
}

RunMonkeyRun() {
    MsgBox("Help me find a banana!", "Support hungry primates")
}

‘Toggle’ is probably the most useful, but they should all work.

Comments (7)

  1. Matt Feemster repo owner

    I’ve committed a fix, please test.

    There seems to be an error in your test. The disable button wires up to the enable event handler, and vice versa. If you get my commit, and untangle this mismatch, it should work.

  2. Winter Laite reporter

    You are absolutely right, the test works as shown above when the event handlers are properly wired. However, from the docs:

        1 or True turns on the setting
        0 or False turns off the setting
        -1 sets it to the opposite of its current state
    

    At least for me, 0 or False both work to disable, -1 works to toggle, but only 1 works to enable ('True' or ‘true’ does not).

  3. Log in to comment