Send("{Click}"), Click() and MouseClick() do not work properly.

Issue #94 closed
Winter Laite created an issue

Script 1 (used to try to work around Issue #88)

MyGui := Gui(, "Some Random Window Title")

BtnVictim := MyGui.Add("Button", "x10 y10", "Target")
BtnVictim.OnEvent("Click", "TargetMessage")

Btn1 := MyGui.Add("Button", "x10 y+10", "Control Click Text")
Btn1.OnEvent("Click", "ClickIt")
Btn2 := MyGui.Add("Button", "x10 y+10", "Control Click Pos")
Btn2.OnEvent("Click", "ClickPos")


MyGui.Show("w400 h200")

ClickIt() {
    Sleep(10)
    ControlClick("Target", "Some Random Window Title",,,, "NA")
}

ClickPos() {
    CoordMode("Mouse", "Client")
    pos := ControlGetPos("Target", "Some Random Window Title")
    Sleep(10)
    SetControlDelay(-1)
    ;posString := "x" pos["X"]+2 " y" pos["Y"]+2
    ;MsgBox(posString)
    ;ControlClick(posString, "Some Random Window Title",,,, "POS")
    MouseMove(pos["X"] + 5, pos["Y"] + 5)
    Send("{Click}")
}

TargetMessage() {
    MsgBox("Victim button clicked")
}

Exception:

************** Exception Text **************
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.InvalidCastException: Unable to cast object of type 'System.Int64' to type 'System.Int32'.

Script 2, MouseClick()

MyGui := Gui(, "Some Random Window Title")

BtnVictim := MyGui.Add("Button", "x10 y10", "Target")
BtnVictim.OnEvent("Click", "TargetMessage")

Btn1 := MyGui.Add("Button", "x10 y+10", "Control Click Text")
Btn1.OnEvent("Click", "ClickIt")
Btn2 := MyGui.Add("Button", "x10 y+10", "Control Click Pos")
Btn2.OnEvent("Click", "ClickPos")


MyGui.Show("w400 h200")

ClickIt() {
    Sleep(10)
    ControlClick("Target", "Some Random Window Title",,,, "NA")
}

ClickPos() {
    CoordMode("Mouse", "Client")
    pos := ControlGetPos("Target", "Some Random Window Title")
    Sleep(10)
    SetControlDelay(-1)
    ;posString := "x" pos["X"]+2 " y" pos["Y"]+2
    ;MsgBox(posString)
    ;ControlClick(posString, "Some Random Window Title",,,, "POS")
    MouseMove(pos["X"] + 5, pos["Y"] + 5)
    ;Send("{Click}")
    MouseClick("L")
}

TargetMessage() {
    MsgBox("Victim button clicked")
}

Mouse does not click after moving to proper coordinates.

Script 3, using Click(). Click occurs, but exception is unhandled.

MyGui := Gui(, "Some Random Window Title")

BtnVictim := MyGui.Add("Button", "x10 y10", "Target")
BtnVictim.OnEvent("Click", "TargetMessage")

Btn1 := MyGui.Add("Button", "x10 y+10", "Control Click Text")
Btn1.OnEvent("Click", "ClickIt")
Btn2 := MyGui.Add("Button", "x10 y+10", "Control Click Pos")
Btn2.OnEvent("Click", "ClickPos")


MyGui.Show("w400 h200")

ClickIt() {
    Sleep(10)
    ControlClick("Target", "Some Random Window Title",,,, "NA")
}

ClickPos() {
    CoordMode("Mouse", "Client")
    pos := ControlGetPos("Target", "Some Random Window Title")
    Sleep(10)
    SetControlDelay(-1)
    ;posString := "x" pos["X"]+2 " y" pos["Y"]+2
    ;MsgBox(posString)
    ;ControlClick(posString, "Some Random Window Title",,,, "POS")
    MouseMove(pos["X"] + 5, pos["Y"] + 5)
    ;Send("{Click}")
    ;MouseClick("L")
    coordstr := pos["X"] " " pos["Y"]
    Click(coordstr)
}

TargetMessage() {
    MsgBox("Victim button clicked")
}

************** Exception Text **************
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.InvalidCastException: Unable to cast object of type 'System.Int64' to type 'System.Int32'.

Comments (3)

  1. Matt Feemster repo owner

    I’ve committed a fix, please test.

    I had to change around some of the underlying mechanics of how we send keyboard and mouse events, but it looks ok on my end. Test around your usual areas and let me know how it looks.

  2. Log in to comment