Jump to content
Sign in to follow this  
ChotolateSad

i have problem with ControlSend

Recommended Posts

ChotolateSad

I want send key to my game,i write code ControlSend($mygametitle,"","","1") ,but not work.I search our forum,i find function _sendkeyplus.I Try with program notepad but it also not work.Can you fix it again or have you got other method send key "1" into game if function ControlSend no work?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <String.au3>
_SendPlus("Untitled - Notepad", "1111")

Func _SendPlus($Window, $text = "")
    Local $WM_KEYDOWN    = 0x0100
    Local $WM_KEYUP        = 0x0101
    Local $WM_CHAR        = 0x0102
    Local $VK_BACK        = 0x08
    Local $VK_TAB        = 0x09
    Local $VK_RETURN    = 0x0d
    Local $VK_SHIFT        = 0x10
    Local $VK_CONTROL    = 0x11
    Local $VK_MENU        = 0x12
    Local $VK_PAUSE        = 0x13
    Local $VK_ESCAPE    = 0x14
    Local $VK_SPACE        = 0x20
    Local $VK_PRIOR        = 0x21
    Local $VK_NEXE        = 0x22
    Local $VK_END        = 0x23
    Local $VK_HOME        = 0x24
    Local $VK_LEFT        = 0x25
    Local $VK_UP        = 0x26
    Local $VK_RIGHT        = 0x27
    Local $VK_DOWN        = 0x28
    Local $VK_SNAPSHOT    = 0x2c
    Local $VK_INSERT    = 0x2d
    Local $VK_DELETE    = 0x2e

      Local $i            = 0
    Local $loc            = 0
    Local $key            = 0
    Local $op            = ""
    Local $string        = StringSplit($text, "")
    For $i = 1 to $string[0]
        If $string[$i] = '{' Then
            $loc = $i
        ElseIf $string[$i] = '}' Then
            $spec = StringMid($text,$loc,$i - $loc + 1)
            $op = $WM_CHAR
            Select
            Case $spec = "{ENTER}"
                $key = $VK_RETURN
            Case $spec = "{SHIFT}"
                $key = $VK_SHIFT
            Case $spec = "{SHIFTDOWN}"
                $key = $VK_SHIFT
                $op = $WM_KEYDOWN
            Case $spec = "{SHIFTUP}"
                $key = $VK_SHIFT
                $op = $WM_KEYUP
            Case $spec = "{CTRL}"
                $key = $VK_CONTROL
            Case $spec = "{CTRLDOWN}"
                $key = $VK_CONTROL
                $op = $WM_KEYDOWN
            Case $spec = "{CTRLUP}"
                $key = $VK_CONTROL
                $op = $WM_KEYUP
            Case $spec = "{ESCAPE}"
                $key = $VK_ESCAPE
            Case $spec = "{SPACE}"
                $key = $VK_SPACE
            Case $spec = "{INSERT}"
                $key = $VK_INSERT
            Case Else
                If $string[$loc + 2] = ' ' Then   ; single car with repetitions or up/down
                    $key = "0x" & _StringToHex($string[$loc + 1])
                Else
                    MsgBox(0,"Error","Unknown cmd *" & $text & "*")
                EndIf
            EndSelect
            DllCall("user32.dll", "int", "SendMessage", _
                "hwnd",  WinGetHandle($Window), _
                "int",   $op, _
                "int",   $key, _
                "long",  1)
            $loc = 0
        ElseIf $loc > 0 Then
                ContinueLoop
        Else
            $key = "0x" & _StringToHex($string[$i])
            DllCall("user32.dll", "int", "SendMessage", _
                "hwnd",  WinGetHandle($Window), _
                "int",   $WM_CHAR, _
                "int",   $key, _
                "long",  1)
        EndIf
    Next
EndFunc
Edited by ChotolateSad

Share this post


Link to post
Share on other sites
Andreik

With notepad this code work fine:

AutoItSetOption("WinTitleMatchMode",2)
Run("notepad")
WinWait("Notepad")
WinActivate("Notepad")
ControlSend("Notepad","","Edit1","This is a test")

Use AutoIt Window Info to get control ID from your game, change the title with your game window title and then run the code to see if works.


When the words fail... music speaks

Share this post


Link to post
Share on other sites
ChotolateSad

With notepad this code work fine:

AutoItSetOption("WinTitleMatchMode",2)
Run("notepad")
WinWait("Notepad")
WinActivate("Notepad")
ControlSend("Notepad","","Edit1","This is a test")

Use AutoIt Window Info to get control ID from your game, change the title with your game window title and then run the code to see if works.

i want to send to windown game with char "1" and i write code in my auto

ControlSend("Mygametitle","","","1")

But it no word

Edited by ChotolateSad

Share this post


Link to post
Share on other sites
Andreik

i want to send to windown game with char "1" and i write code in my auto

ControlSend("Mygametitle","","","1")

But it no word

Are some programs/games that protects the things like ControlSend() or ControlClick ().

Maybe this is one of this.


When the words fail... music speaks

Share this post


Link to post
Share on other sites
ChotolateSad

yes, i known that,so i looking for method to send key to my game.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.