'Autoit ControlSend

Just trying to simulate keystrokes with ControlSend(). For some reason it doesn't work.

While 1
   ControlSend("PokeMMO", "", "", "{DOWN}")
   Sleep(900)
   ControlSend("PokeMMO", "", "", "{DOWN}")
   Sleep(900)
   ControlSend("PokeMMO", "", "", "{DOWN}")
   Sleep(900)
   ControlSend("PokeMMO", "", "", "a")
   Sleep(Random(750, 2000, 1))
   ControlSend("PokeMMO", "", "", "a")
   Sleep(Random(750, 2000, 1))
   ControlSend("PokeMMO", "", "", "a")
   Sleep(Random(750, 2000, 1))
   ControlSend("PokeMMO", "", "", "a")
   Sleep(3000)
WEnd

Au3Info:

Title: РokеММO,
Class: LWJGL

Global $sProcess = "javaw.exe" ;PokeMMO Process

ControlSend(_Process2Win($sProcess), "", "", "{DOWN}")

Func _Process2Win($pid)
    If IsString($pid) Then $pid = ProcessExists($pid)
    If $pid = 0 Then Return -1
    $list = WinList()
    For $i = 1 To $list[0][0]
        If $list[$i][0] <> "" And BitAND(WinGetState($list[$i][1]), 2) Then
            $wpid = WinGetProcess($list[$i][0])
            If $wpid = $pid Then Return $list[$i][0]
        EndIf
    Next
    Return -1
EndFunc   ;==>_Process2Win


Solution 1:[1]

You can use WinGetHandle first to recieve a handle to the Window and then use this handle in the ControlSend function, which should work. It looks like the following:

$handle = WinGetHandle("[TITLE:PokeMMO; CLASS:LWJGL]")
ControlSend($handle, Default, $handle, "{Down}")

Try to display the content of handle first to confirm, you're recieving a working handle. Like ConsoleWrite($handle) or MsgBox(1, "Handle", WinGetTitle($handle))

Go, give it a try ;-)
And good luck!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Samoth