Jump to content

ControlSend() MaDnESS


NoHAX
 Share

Recommended Posts

Hi everyone

Again with my program

#include-once
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIonEventMode", 1)
Opt("MouseCoordMode", 0)
Opt("WinTitleMatchMode", 3)
Opt("SendAttachMode", 0)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AutoBonner v1.2 by NoHax", 491, 451, 192, 124)
GUISetBkColor(0x000000)
$Button1 = GUICtrlCreateButton("Run", 304, 344, 161, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Exit", 304, 408, 161, 25, $WS_GROUP)
$Button3 = GUICtrlCreateButton("Options", 304, 376, 161, 25, $WS_GROUP)
GUISetState(@SW_SHOW, $Form1)
$Form2 = GUICreate("Options", 380, 300, 702, 279)
GUISetBkColor(0x000000)
$Input1 = GUICtrlCreateInput("", 12, 23, 169, 21)
$Input2 = GUICtrlCreateInput("", 12, 71, 169, 21)
$Label1 = GUICtrlCreateLabel("Time between bw (more then 24s)", 12, 55, 164, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
$Button1a = GUICtrlCreateButton("OK", 133, 256, 120, 33, $WS_GROUP)
$Label2 = GUICtrlCreateLabel("Text added after bw (optionally)", 12, 200, 152, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
$Label3 = GUICtrlCreateLabel("Number of bws", 12, 8, 75, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
$Input3 = GUICtrlCreateInput("", 12, 216, 169, 21)
$Label4 = GUICtrlCreateLabel("Diablo II window name", 12, 104, 111, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
$Input4 = GUICtrlCreateInput("", 12, 120, 169, 21)
$Label5 = GUICtrlCreateLabel("Bonewall hotkey", 12, 152, 82, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
$Input5 = GUICtrlCreateInput("", 12, 168, 169, 21)
$Label6 = GUICtrlCreateLabel("Script wrote in AutoIT" & @CRLF & "Author: NoHax" & @CRLF & "Redgrds to all my friends :)", 208, 20, 391, 90)
GUICtrlSetColor(-1, 0xFFFFFF)
GUISetState(@SW_HIDE, $Form2)
GUICtrlSetOnEvent($Button1, "_run")
GUICtrlSetOnEvent($Button2, "_exit")
GUICtrlSetOnEvent($Button3, "_options")
GUICtrlSetOnEvent($Button1a, "_OK")
#EndRegion ### END Koda GUI section ###

DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd

Func _options() 
    GUISetState(@SW_SHOW, $Form2)
EndFunc

Func _OK()
        GUISetState(@SW_HIDE, $Form2)
        Sleep(100)
        GUISetState(@SW_SHOW, $Form1)
EndFunc
    
Func _exit()
    MsgBox(0, "Cu", "If you found any bugs, pls send me on CRC_3rror@yahoo.com :)")
    Exit
EndFunc


Func _run()
$title = GUICtrlRead($Input4)
$time = GUICtrlRead($Input2)
$bwkey = GUICtrlRead($Input5)
$text = GUICtrlRead($Input3)
$bw = GUICtrlRead($Input1)
$hwnd = WinGetHandle($title)

GUICtrlSetState($button3, $Gui_disable)

    For $s=1 To $bw Step 1
    Sleep(300)
    ControlSend($hwnd, '', '',$bwkey)
    Sleep(300)
    _MouseClickPlus($hwnd, "right", 536, 233, 1)
    Sleep(400)
    ControlSend($Title, '', '', '{Enter}')
    Sleep(Random(100,200))
    ControlSend($Title, '', '',$s+1)
        Sleep(Random(100,200))
    ControlSend($Title, '', '',', ')
        Sleep(Random(100,200))
    ControlSend($Title, "", "",$text)
        Sleep(Random(100,200))
    ControlSend($Title, '', '','{Enter}')
    Sleep($Time * 1000)
Next
SoundPlay(@WindowsDir & "\media\tada.wav",1)
EndFunc


;===============================================================================
  ;
  ; Function Name:  _MouseClickPlus()
  ; Version added:  0.1
  ; Description:    Sends a click to window, not entirely accurate, but works 
  ;                 minimized.
  ; Parameter(s):   $Window     =  Title of the window to send click to
  ;                 $Button     =  "left" or "right" mouse button
  ;                 $X          =  X coordinate
  ;                 $Y          =  Y coordinate
  ;                 $Clicks     =  Number of clicks to send
  ; Remarks:        You MUST be in "MouseCoordMode" 0 to use this without bugs.
  ; Author(s):      Insolence <insolence_9@yahoo.com>
  ;
  ;===============================================================================
 Func _MouseClickPlus($Window, $Button = "left", $X = "", $Y = "", $Clicks = 1)
    Local $MK_LBUTTON       =  0x0001
    Local $WM_LBUTTONDOWN   =  0x0201
    Local $WM_LBUTTONUP     =  0x0202
    
    Local $MK_RBUTTON       =  0x0002   
    Local $WM_RBUTTONDOWN   =  0x0204
    Local $WM_RBUTTONUP     =  0x0205
 
    Local $WM_MOUSEMOVE     =  0x0200
    
    Local $i                = 0
    
    Select 
    Case $Button = "left"
       $Button     =  $MK_LBUTTON
       $ButtonDown =  $WM_LBUTTONDOWN
       $ButtonUp   =  $WM_LBUTTONUP
    Case $Button = "right"
       $Button     =  $MK_RBUTTON
       $ButtonDown =  $WM_RBUTTONDOWN
       $ButtonUp   =  $WM_RBUTTONUP
    EndSelect
    
    If $X = "" OR $Y = "" Then
       $MouseCoord = MouseGetPos()
       $X = $MouseCoord[0]
       $Y = $MouseCoord[1]
    EndIf
    
    For $i = 1 to $Clicks
       DllCall("user32.dll", "int", "SendMessage", _
          "hwnd",  WinGetHandle( $Window ), _
          "int",   $WM_MOUSEMOVE, _
          "int",   0, _
          "long",  _MakeLong($X, $Y))
          
       DllCall("user32.dll", "int", "SendMessage", _
          "hwnd",  WinGetHandle( $Window ), _
          "int",   $ButtonDown, _
          "int",   $Button, _
          "long",  _MakeLong($X, $Y))
          
       DllCall("user32.dll", "int", "SendMessage", _
          "hwnd",  WinGetHandle( $Window ), _
          "int",   $ButtonUp, _
          "int",   $Button, _
          "long",  _MakeLong($X, $Y))
    Next
EndFunc

 Func _MakeLong($LoWord,$HiWord)
    Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc

And AutoIT Window Tool show me

>>>> Window <<<<
Title:  Diablo II
Class:  Diablo II
Position:   360, 131
Size:   806, 626
Style:  0x14C00000
ExStyle:    0x00040100
Handle: 0x000E0118

>>>> Control <<<<
Class:  
Instance:   
ClassnameNN:    
Advanced (Class):   
ID: 
Text:   
Position:   
Size:   
ControlClick Coords:    
Style:  
ExStyle:    
Handle: 0x000100B4

>>>> Mouse <<<<
Position:   293, 234
Cursor ID:  2
Color:  0x7C7470

>>>> StatusBar <<<<

>>>> Visible Text <<<<


>>>> Hidden Text <<<<

The problem is again with "ControlSend()". Many peoples on this forum have this problem unsolved :\ I used this function few weeks ago and it works fine, but now i try with exactly same method. :P

Need ControlSetText?

I working under Vista Homce Basic (added to my laptop).

Where is the reason of all this ControlSend problems :idea:

I cant use ControlID if i dont have controlID ^^ so i left ' "" '

Ahh and second thing :)

Is there any way to remember text what you put to inputs? it is boring to always write informations to Gui. I think about something like cookies for $Input :)

Link to comment
Share on other sites

  • Developers

Please do not bump your thread within 24 hours.

Why would ControlSend() be broken? I do not see any reference to any control in the shown capture.

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Sorry. i must insert controlgetfocus? maybe i forget something, but whatever this was, i dont used it in older program who still is working perfect. If i wrote something wrong then sorry, i using mobile phone now :\

Link to comment
Share on other sites

First things first, since you have no info about the control, work on getting the handle using ControlGetHandle() then you can pass that to ControlSend().

There are some other functions that are helpful to get the handle that you can search for. _CtrlGetByPos(), _WinGetCtrlInfo() and I have "Control Handle under mouse" in my sig.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

I used ControlFocus (maybe wrong, i dont know) and Script looks like

Func _run()
ConsoleWrite("Reading _run()" & @CRLF)

$bw = GUICtrlRead($Input1)
$time = IsFloat(GUICtrlRead($Input2))
$text = GUICtrlRead($Input3)
$title = GUICtrlRead($Input4)
$bwkey = GUICtrlRead($Input5)
$hwnd = WinGetHandle($title)

GUICtrlSetState($button3, $Gui_disable)

ConsoleWrite("Start For Loop" & @CRLF)
For $s=1 To $bw Step 1
    ControlFocus($Title, "", $s & $text & $bwkey)
    Sleep(300)
    ControlSend($title, "", "",$bwkey)
    Sleep(300)
    _MouseClickPlus($hwnd, "right", 536, 233, 1)
    Sleep(400)
    ControlSend($title, "", "", "{Enter}")
    Sleep(Random(100,200))
    ControlSend($title, "", "",$s)
        Sleep(Random(100,200))
    ControlSend($title, "", "",", ")
        Sleep(Random(100,200))
    ControlSend($title, "", "", $text)
        Sleep(Random(100,200))
    ControlSend($title, "", "","{Enter}")
    Sleep($Time * 1000)
Next
GUICtrlSetState($button3, $Gui_enable)
SoundPlay(@WindowsDir & "\media\tada.wav",1)
ConsoleWrite("End of the script" & @CRLF)
EndFunc

Still doesnt work :)

My window doesnt have any control info from AutoIt Window Info.exe

>>>> Control <<<<
Class:  
Instance:   
ClassnameNN:    
Advanced (Class):   
ID: 
Text:   
Position:   
Size:   
ControlClick Coords:    
Style:  
ExStyle:    
Handle: 0x000100B4

Hmm co i dont know how your functions from sig can help me if my >>>> Control <<<< show nothing :/

Link to comment
Share on other sites

Hmmmm maybe i quote bo8ster from other topic :)

This is simple.

1.) Use ControlGetHandle to ensure you are getting the correct handle

2.) ControlSend to Notepad to ensure the right text is being sent.

3.) Use WinSetState to control the window.

4.) Worse comes to worse, every control has a handle that can be used and there are always mouse commands to get the focus.

4.) ControlFocus - not going to work if the parent window is not in active.

Try this :)

This world is crazy

Link to comment
Share on other sites

Hmmmm maybe i quote bo8ster from other topic :)

Try this :)

Thx for help, but i think i try with all of these things

Anyway i get "0x00100220" by "ControlGetHandle" and what i must do with this? i tryied

ControlSend($title, "", 0x00080466, "{Enter}" & "This is some text"); i get 0x00080466 from AutoIt Window Info, but 0x00100220 doesnt work to :P

I think this is impossible xDD

Link to comment
Share on other sites

This makes total sense - ControlSend($title, "", 0x00080466, "{Enter}" & "This is some text") sends text to the Window, at no time do you reference the Control, you don't get past point 1.

Hmm co i dont know how your functions from sig can help me if my >>>> Control <<<< show nothing :/

Thats because you don't know how it works, nor do you know how SmOke_N's functions work. Now my function may not be able to help you have you tried _CtrlGetByPos()? This function uses mouse coords.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

also try this. I know AutoIt Info Window gives you no class name but I have noticed differences between what what AutoIt and the Info tool does. To be honest I have no idea how the AutoIt Info tool does it but I would like to know. Worth a try :)

AutoItSetOption("MouseCoordMode", 2)
AdlibEnable("_Mouse_Control_GetInfoAdlib", 10)

While 1
    Sleep(0xFFFFFFF)
WEnd
Func _Mouse_Control_GetInfoAdlib()
    Local $a_info = _Mouse_Control_GetInfo()
    If @error Then Return
    ToolTip("Handle = " & $a_info[0] & @CRLF & _
        "Class = " & $a_info[1] & @CRLF & _
        "Mouse X Pos = " & $a_info[2] & @CRLF & _
        "Mouse Y Pos = " & $a_info[3])
EndFunc

Func _Mouse_Control_GetInfo()
    local $client_mpos = MouseGetPos() ; gets client coords because of "MouseCoordMode" = 2
    Local $a_mpos = _ClientToScreen($appHandle, $client_mpos[0], $client_mpos[1]) ; $a_mpos now screen coords   
    If @error Then Return SetError(1, 0, 0)
    Local $a_wfp = DllCall("user32.dll", "hwnd", "WindowFromPoint", "long", $a_mpos[0], "long", $a_mpos[1])
    If @error Then Return SetError(2, 0, 0)
    Local $t_class = DllStructCreate("char[260]")
    DllCall("User32.dll", "int", "GetClassName", "hwnd", $a_wfp[0], "ptr", DllStructGetPtr($t_class), "int", 260)
    Local $a_ret[4] = [$a_wfp[0], DllStructGetData($t_class, 1), $a_mpos[0], $a_mpos[1]]
    Return $a_ret
EndFunc
; ===============================================================================
;~ Translates client coordinates into screen coordinates, [0] = x and [1] = y from the return array.
;~ Requires - AutoItSetOption("MouseCoordMode", 2)
;~ Params
;~      $h_wnd - Identifies the window whose client area is used for the conversion.
;~      $i_x - x pos of the client coord
;~      $i_y - Y pos of the client coord
;~ Returns - 
; ===============================================================================
Func _ClientToScreen($h_wnd, $i_x, $i_y)
    ConsoleWrite("here, " & $i_x & "," & $i_y & @CRLF)
    Local $t_point = DllStructCreate("int;int")
    
    DllStructSetData($t_point, 1, $i_x)
    DllStructSetData($t_point, 2, $i_y)
    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $h_wnd, "ptr", DllStructGetPtr($t_point))
    
    Local $a_ret[2] = [DllStructGetData($t_point, 1), DllStructGetData($t_point, 2)]
    ConsoleWrite("here, " & $a_ret[0] & "," & $a_ret[1] & @CRLF)
    Return $a_ret
EndFunc

_WinGetCtrlInfo() is also another one of SmOke_N's functions worth looking into here. Edited by bo8ster

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Ok i used it and i get this informations (btw very useful function :) )

Handle = 0x00070EDA
Class = Scintilla
ClassNN = Scintilla1
ID = 350
Mouse X pos = 176
Mouse Y pos = 193
Parent Hwd = 0x000C0016

And i think i must insert this informations to

ControlSend ( "title", "text", controlID, "string" [, flag] )

I tried this:

ControlSend($title, "", 350, "{Enter}" & "This is some text")

ControlSend($title, "", "[iD:350]", "{Enter}" & "This is some text")

ControlSend($title, "", 0x00070EDA, "{Enter}" & "This is some text")

ControlSend($title, "", 0x00070EDA, "{Enter}" & "This is some text")

ControlSend($title, "", "[CLASS:Scitilla]", "{Enter}" & "This is some text")

ControlSend($title, "", "[CLASS:Scitilla1]", "{Enter}" & "This is some text")

I forget something?

What Jos have mean by "I do not see any reference to any control in the shown capture.". If it is ControlFocus then i tryied :\

Hmmm maybe i doing something wrong, but i read this Control functions every day...

Link to comment
Share on other sites

Jos says it because of your code, post #1.

$title = GUICtrlRead($Input4)
...
$hwnd = WinGetHandle($title)

You only reference a Window Handle, never a control handle and this is still the case. $title is a string (I assume) and $hwnd is a Window handle.

Yes the help file syntax is correct by you want to use control handles so you use a different method described in the Controls Section at the bottom "Control Handle (HWND)".

Remembering handles are dynamic so they will change each time you load the app, do the following.

Local $ctrlHwd = $a_info[0] ; the control handle, this would be the same as ControlGetHandle()
ControlSend($ctrlHwd , "", "", "{Enter}")
ControlSend($ctrlHwd , "", "", "This is some text") ; try breaking it up too.
ConsoleWrite($ctrlHwd) ; compare witht the output given from the Info Tool

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Hmmm

Can you write short function who will write "Hello Word" to minimized game window? (on example game window name is "GetThis") and in window info we have

>>>> Control <<<<
Class:  
Instance:   
ClassnameNN:    
Advanced (Class):   
ID: 
Text:   
Position:   
Size:   
ControlClick Coords:    
Style:  
ExStyle:    
Handle: 0x00210F5C
[code=auto:0]

Functions get Windowname from $input1 and text to write from $input2

Anyway thanks for help in this crazy topic 


            
        

        

        
    

    

    




    Link to comment
    
        
    
    
    

    
    Share on other sites
    

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    


    
    More sharing options...

    


    

                    
                    
                    
                

                    

                    
                    





    

    

    
        
            
                


    
        
    

                
                
                    
                        

                    
                
            
        
        
            
                


bo8ster
            
            
                Posted 
                
            
        
    
    
        


bo8ster
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                Active Members
                
            
            
                
                    
                        
                            
                                
                            
                                 1.2k
                            
                                
                            
                        
                        
                    
                
            
            
                

            
        
    
    
        



    
        
            
                
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                            Share
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
            Posted 
            
            
                
                
            
        
    

    

    

    
        
        
            Using the methods I showed you, you will need to have the Window in focus in order to get the handle. Can you do that with the given control?
I don't do much GUI work in AutoIt, seems like you are most of the way there with what you had.


            
        

        

        
            

    
        

        
            Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic],  [topic="93527"]Control Handle under mouse[/topic],  [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]
        
    

        
    

    

    




    Link to comment
    
        
    
    
    

    
    Share on other sites
    

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    


    
    More sharing options...

    


    

                    
                        
                            
                            
                                
                                    2 weeks later...
                                
                            
                        
                    
                    
                    
                

                    

                    
                    





    

    

    
        
            
                


    
        
    

                
                
                    
                        

                    
                
            
        
        
            
                


usabrad86
            
            
                Posted 
                
            
        
    
    
        


usabrad86
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                Members
                
            
            
                
                    
                        
                            
                                
                            
                                 14
                            
                                
                            
                        
                        
                    
                
            
            
                

            
        
    
    
        



    
        
            
                
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                            Share
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
            Posted 
            
            
                
                
            
        
    

    

    

    
        
        
            i found a autoit program called KCH ...  the source had _sendminimize.au3 for diablo 2

i think this is exactly what your looking for


            
        

        

        
    

    

    




    Link to comment
    
        
    
    
    

    
    Share on other sites
    

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    


    
    More sharing options...

    


    

                    
                    
                    
                

                    

                    
                    





    

    

    
        
            
                


    
        
    

                
                
                    
                        

                    
                
            
        
        
            
                


usabrad86
            
            
                Posted 
                
            
        
    
    
        


usabrad86
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                Members
                
            
            
                
                    
                        
                            
                                
                            
                                 14
                            
                                
                            
                        
                        
                    
                
            
            
                

            
        
    
    
        



    
        
            
                
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                            Share
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
            Posted 
            
            
                
                
            
        
    

    

    

    
        
        
            This is MinimizedMsg.au3 = from KCH2.0

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------
#include-once

; Script Start - Add your code below here

#cs
Global $VK_TAB          =  0x09
Global $VK_CLEAR        =  0x0C
Global $VK_RETURN       =  0x0D
Global $VK_SHIFT        =  0x10
Global $VK_CONTROL      =  0x11
Global $VK_ESCAPE       =  0x1B
Global $VK_SPACE        =  0x20
Global $VK_LEFT         =  0x25
Global $VK_UP           =  0x26
Global $VK_RIGHT        =  0x27
Global $VK_DOWN         =  0x28
Global $VK_DELETE       =  0x2E
Global $VK_0            =  0x30
Global $VK_1            =  0x31
Global $VK_2            =  0x32
Global $VK_3            =  0x33
Global $VK_4            =  0x34
Global $VK_5            =  0x35
Global $VK_6            =  0x36
Global $VK_7            =  0x37
Global $VK_8            =  0x38
Global $VK_9            =  0x39
Global $VK_A            =  0x41
Global $VK_B            =  0x42
Global $VK_C            =  0x43
Global $VK_D            =  0x44
Global $VK_E            =  0x45
Global $VK_F            =  0x46
Global $VK_G            =  0x47
Global $VK_H            =  0x48
Global $VK_I            =  0x49
Global $VK_J            =  0x4A
Global $VK_K            =  0x4B
Global $VK_L            =  0x4C
Global $VK_M            =  0x4D
Global $VK_N            =  0x4E
Global $VK_O            =  0x4F
Global $VK_P            =  0x50
Global $VK_Q            =  0x51
Global $VK_R            =  0x52
Global $VK_S            =  0x53
Global $VK_T            =  0x54
Global $VK_U            =  0x55
Global $VK_V            =  0x56
Global $VK_W            =  0x57
Global $VK_X            =  0x58
Global $VK_Y            =  0x59
Global $VK_Z            =  0x5A
Global $VK_NUMPAD0      =  0x60
Global $VK_NUMPAD1      =  0x61
Global $VK_NUMPAD2      =  0x62
Global $VK_NUMPAD3      =  0x63
Global $VK_NUMPAD4      =  0x64
Global $VK_NUMPAD5      =  0x65
Global $VK_NUMPAD6      =  0x66
Global $VK_NUMPAD7      =  0x67
Global $VK_NUMPAD8      =  0x68
Global $VK_NUMPAD9      =  0x69
Global $VK_MULTIPLY     =  0x6A
Global $VK_ADD          =  0x6B
Global $VK_SEPARATOR    =  0x6C
Global $VK_SUBTRACT     =  0x6D
Global $VK_DECIMAL      =  0x6E
Global $VK_DIVIDE       =  0x6F
Global $VK_F1           =  0x70
Global $VK_F2           =  0x71
Global $VK_F3           =  0x72
Global $VK_F4           =  0x73
Global $VK_F5           =  0x74
Global $VK_F6           =  0x75
Global $VK_F7           =  0x76
Global $VK_F8           =  0x77
Global $VK_F9           =  0x78
Global $VK_F10          =  0x79
Global $VK_F11          =  0x7A
Global $VK_F12          =  0x7B
Global $VK_F13          =  0x7C
Global $VK_F14          =  0x7D
Global $VK_F15          =  0x7E
Global $VK_F16          =  0x7F
Global $VK_F17          =  0x80
Global $VK_F18          =  0x81
Global $VK_F19          =  0x82
Global $VK_F20          =  0x83
Global $VK_F21          =  0x84
Global $VK_F22          =  0x85
Global $VK_F23          =  0x86
Global $VK_F24          =  0x87
Global $VK_NUMLOCK      =  0x90
Global $VK_SCROLL       =  0x91

Global $VK_OEM_NEC_EQUAL = 0x92   ;// '=' key on numpad

Global $VK_OEM_1         = 0xBA   ;// ';:' for US
Global $VK_OEM_PLUS      = 0xBB   ;// '+' any country
Global $VK_OEM_COMMA     = 0xBC   ;// ',' any country
Global $VK_OEM_MINUS     = 0xBD   ;// '-' any country
Global $VK_OEM_PERIOD    = 0xBE   ;// '.' any country
Global $VK_OEM_2         = 0xBF   ;// '/?' for US
Global $VK_OEM_3         = 0xC0   ;// '`~' for US

Global $VK_OEM_4         = 0xDB  ;//  '[{' for US
Global $VK_OEM_5         = 0xDC  ;//  '\|' for US
Global $VK_OEM_6         = 0xDD  ;//  ']}' for US
Global $VK_OEM_7         = 0xDE  ;//  ''"' for US
Global $VK_OEM_8         = 0xDF

Global $VK_OEM_102       = 0xE2  ;//  "<>" or "\|" on RT 102-key kbd.
Global $VK_ICO_HELP      = 0xE3  ;//  Help key on ICO
Global $VK_ICO_00        = 0xE4  ;//  00 key on ICO
Global $VK_OEM_BACKTAB   = 0xF5
#ce

;~ Global $WM_KEYDOWN       = 0x0100 ;;declared in WindowConstants.au3
;~ Global $WM_KEYUP         = 0x0101 ;;declared in WindowConstants.au3


;~ _SendMinimizedMessage(WinGetHandle("Diablo II"),"test")

Func _SendMinimizedMessage($winhandle,$msgstring,$raw = 0)
    If $winhandle = "" Then
        ;; illegal number of parameters?
;~         MsgBox(32, "KCH: Problem", "SendMinimizedMessage() called with bad number of params?")
        Return
    EndIf
    Local $i = 0
    while $i < StringLen($msgstring)
        $i = $i + 1
        Local $var = StringMid($msgstring,$i,1)
        if $raw = 1 Then
            _SendMinimizedVK($winhandle,StringMid($msgstring,$i,1))
        Else
            if $var = "{" Then
                Local $var2 = StringInStr(StringMid($msgstring,$i+1),"}",2)
                _SendMinimizedVK($winhandle,StringMid($msgstring,$i+1,$var2-1))
                $i = $i + $var2
            Else
                _SendMinimizedVK($winhandle,StringMid($msgstring,$i,1))
            EndIf
        EndIf
        Sleep(50)
    WEnd
    Return
EndFunc

Func _SendMinimizedVK($winhandle,$vkstring)
    Local $var = _GetHexByKey_Switch($vkstring)
    if Not ($var = -1) Then
        DllCall("user32.dll", "int", "SendMessage", _
        "hwnd", $winhandle, _
        "int", $WM_KEYDOWN, _
        "int", _GetHexByKey_Switch($vkstring), _
        "long", 0)
        DllCall("user32.dll", "int", "PostMessage", _ ;SendMessage only works ingame, not in lobby
        "hwnd", $winhandle, _
        "int", $WM_KEYUP, _
        "int", _GetHexByKey_Switch($vkstring), _
        "long", 0) 
;~      ConsoleWrite(1 & @CRLF) ;debug Success
        Return 1
    EndIf
;~  ConsoleWrite(0 & @CRLF) ;debug Failed
    Return 0
EndFunc

Func _GetHexByKey_Switch($sKey)
    Switch $sKey
        Case "LeftMouse"            
            Return 0x01 
        Case "RightMouse"           
            Return 0x02     
        Case "MiddleMouse"          
            Return 0x04     
        Case "X1Mouse"          
            Return 0x05     
        Case "X2Mouse"          
            Return 0x06     
        Case "BACKSPACE"            
            Return 0x08     
        Case "TAB"          
            Return 0x09     
        Case "CLEAR"            
            Return 0x0C     
        Case "ENTER"            
            Return 0x0D     
        Case "SHIFT"            
            Return 0x10     
        Case "CTRL"         
            Return 0x11     
        Case "ALT"          
            Return 0x12     
        Case "PAUSE"            
            Return 0x13     
        Case "CAPSLOCK"         
            Return 0x14     
        Case "ESC"          
            Return 0x1B     
        Case " "            
            Return 0x20 
        Case "SPACE"            
            Return 0x20     
        Case "PAGE UP"          
            Return 0x21     
        Case "PAGE DOWN"            
            Return 0x22     
        Case "END"          
            Return 0x23     
        Case "HOME"         
            Return 0x24     
        Case "LEFT"         
            Return 0x25     
        Case "UP"           
            Return 0x26     
        Case "RIGHT"            
            Return 0x27     
        Case "DOWN"         
            Return 0x28     
        Case "SELECT"           
            Return 0x29     
        Case "PRINT"            
            Return 0x2A     
        Case "EXECUTE"          
            Return 0x2B     
        Case "PRINT SCREEN"         
            Return 0x2C     
        Case "INS"          
            Return 0x2D     
        Case "DEL"          
            Return 0x2E     
        Case "0"            
            Return 0x30     
        Case "1"            
            Return 0x31     
        Case "2"            
            Return 0x32     
        Case "3"            
            Return 0x33     
        Case "4"            
            Return 0x34     
        Case "5"            
            Return 0x35     
        Case "6"            
            Return 0x36     
        Case "7"            
            Return 0x37     
        Case "8"            
            Return 0x38     
        Case "9"            
            Return 0x39     
        Case "A"            
            Return 0x41     
        Case "B"            
            Return 0x42     
        Case "C"            
            Return 0x43     
        Case "D"            
            Return 0x44     
        Case "E"            
            Return 0x45     
        Case "F"        
            Return 0x46     
        Case "G"            
            Return 0x47     
        Case "H"            
            Return 0x48     
        Case "I"            
            Return 0x49     
        Case "J"            
            Return 0x4A     
        Case "K"            
            Return 0x4B     
        Case "L"            
            Return 0x4C     
        Case "M"            
            Return 0x4D     
        Case "N"            
            Return 0x4E     
        Case "O"            
            Return 0x4F     
        Case "P"            
            Return 0x50     
        Case "Q"            
            Return 0x51     
        Case "R"            
            Return 0x52     
        Case "S"            
            Return 0x53     
        Case "T"            
            Return 0x54     
        Case "U"            
            Return 0x55     
        Case "V"            
            Return 0x56     
        Case "W"            
            Return 0x57     
        Case "X"            
            Return 0x58     
        Case "Y"            
            Return 0x59     
        Case "Z"            
            Return 0x5A     
        Case "LWin"         
            Return 0x5B     
        Case "RWin"         
            Return 0x5C     
        Case "NUMPAD0"          
            Return 0x60     
        Case "NUMPAD1"          
            Return 0x61     
        Case "NUMPAD2"          
            Return 0x62     
        Case "NUMPAD3"          
            Return 0x63     
        Case "NUMPAD4"          
            Return 0x64     
        Case "NUMPAD5"          
            Return 0x65     
        Case "NUMPAD6"          
            Return 0x66     
        Case "NUMPAD7"          
            Return 0x67     
        Case "NUMPAD8"          
            Return 0x68     
        Case "NUMPAD9"          
            Return 0x69     
        Case "Multiply"         
            Return 0x6A     
        Case "Add"          
            Return 0x6B     
        Case "Separator"            
            Return 0x6C     
        Case "Subtract"         
            Return 0x6D     
        Case "Decimal"          
            Return 0x6E     
        Case "Divide"           
            Return 0x6F     
        Case "F1"           
            Return 0x70     
        Case "F2"           
            Return 0x71     
        Case "F3"           
            Return 0x72     
        Case "F4"           
            Return 0x73     
        Case "F5"           
            Return 0x74     
        Case "F6"           
            Return 0x75     
        Case "F7"           
            Return 0x76     
        Case "F8"           
            Return 0x77     
        Case "F9"           
            Return 0x78     
        Case "F10"          
            Return 0x79     
        Case "F11"          
            Return 0x7A     
        Case "F12"          
            Return 0x7B     
        Case "F13"          
            Return 0x7C     
        Case "F16"          
            Return 0x7F     
        Case "F17"          
            Return 0x80 
        Case "F18"          
            Return 0x81
        Case "F19"          
            Return 0x82 
        Case "F20"          
            Return 0x83 
        Case "F21"          
            Return 0x84 
        Case "F22"          
            Return 0x85 
        Case "F23"          
            Return 0x86     
        Case "F24"          
            Return 0x87     
        Case "NUM LOCK"         
            Return 0x90 
        Case "SCROLL LOCK"          
            Return 0x91     
        Case "LSHIFT"           
            Return 0xA0     
        Case "RSHIFT"           
            Return 0xA1     
        Case "LCTRL"            
            Return 0xA2     
        Case "RCTRL"            
            Return 0xA3     
        Case "LMENU"            
            Return 0xA4     
        Case "RMENU"            
            Return 0xA5     
        Case "="
            Return 0x92
        Case ";"
            Return 0xBA
        Case ":"
            Return 0xBA
        Case "+"
            Return 0xBB
        Case ","
            Return 0xBC
        Case "-"
            Return 0xBD
        Case "."
            Return 0xBE
        Case "/"
            Return 0xBF
        Case "?"
            Return 0xBF
        Case "`"
            Return 0xC0
        Case "~"
            Return 0xC0
        Case "["
            Return 0xDB
        Case "{"
            Return 0xDB
        Case "\"
            Return 0xDC
        Case "|"
            Return 0xDC
        Case "]"
            Return 0xDD
        Case "}"
            Return 0xDD
        Case "'"
            Return 0xDE
        Case '"'
            Return 0xDE
        Case "<"
            Return 0xE2
        Case ">"
            Return 0xE2
    EndSwitch
    Return -1
EndFunc   ;==>_GetHexByKey_Switch

;===============================================================================
;
; Function Name:  _MouseClickMinimized()
; Version added:  0.1
; Description:    Sends a click to window, not entirely accurate, but works
;                 minimized.
; Parameter(s):   $Window     =  Title of the window to send click to
;                 $Button     =  "left" or "right" mouse button
;                 $X          =  X coordinate
;                 $Y          =  Y coordinate
;                 $Clicks     =  Number of clicks to send
; Remarks:        You MUST be in "MouseCoordMode" 0 (cpf: or 2???) to use this without bugs.
; Author(s):      Insolence <insolence_9@yahoo.com>
;
;===============================================================================
Func _MouseClickMinimized($Window, $Button = "left", $X = "", $Y = "", $Clicks = 1, $handle = 0)
    Local $MK_LBUTTON = 0x0001
    Local $WM_LBUTTONDOWN = 0x0201
    Local $WM_LBUTTONUP = 0x0202
    Local $MK_RBUTTON = 0x0002
    Local $WM_RBUTTONDOWN = 0x0204
    Local $WM_RBUTTONUP = 0x0205
    Local $WM_MOUSEMOVE = 0x0200
    Local $i = 0
    if $handle = 1 Then
        Local $winhandle = $Window
    Elseif $handle = 0 Then
        Local $winhandle = WinGetHandle($Window)
    EndIf
    Select
        Case $Button = "right"
            $Button = $MK_RBUTTON
            $ButtonDown = $WM_RBUTTONDOWN
            $ButtonUp = $WM_RBUTTONUP
        Case $Button = "left"
            $Button = $MK_LBUTTON
            $ButtonDown = $WM_LBUTTONDOWN
            $ButtonUp = $WM_LBUTTONUP
        Case Else  ;; CPF
            ;; illegal number of parameters?
;~             MsgBox(32, "KCH: Problem", "_MouseClickPlus() called with bad number of params?")
            Return
    EndSelect
    ;; makes no sense to send click to minimized window with current mouse coordinates
    If $X = "" Or $Y = "" Then
        ;; illegal number of parameters?
;~         MsgBox(32, "KCH: Problem", "_MouseClickPlus() called with bad number of params?")
        Return
    EndIf
    For $i = 1 To $Clicks
        DllCall("user32.dll", "int", "SendMessage", _
                "hwnd", $winhandle, _
                "int", $WM_MOUSEMOVE, _
                "int", 0, _
                "long", _MakeLong($X, $Y))
        DllCall("user32.dll", "int", "SendMessage", _
                "hwnd", $winhandle, _
                "int", $ButtonDown, _
                "int", $Button, _
                "long", _MakeLong($X, $Y)) 
        Sleep(10)
        DllCall("user32.dll", "int", "SendMessage", _
                "hwnd", $winhandle, _
                "int", $ButtonUp, _
                "int", $Button, _
                "long", _MakeLong($X, $Y)) 
    Next
EndFunc   ;==>_MouseClickMinimized

;===============================================================================
;
; Function Name:  _MouseMoveMinimized()
; Version added:  0.1
; Description:    Sends a move message to window, works minimized.
; Parameter(s):   $Window     =  Title of the window to send click to
;                 $X          =  X coordinate
;                 $Y          =  Y coordinate
; Remarks:        You MUST be in "MouseCoordMode" 0 (cpf: or 2???) to use this without bugs.
; Author(s):      Cris Fuhrman (based on code by Insolence <insolence_9@yahoo.com>)
;
;===============================================================================
Func _MouseMoveMinimized($Window, $X = "", $Y = "", $handle = 0)
    Local $WM_MOUSEMOVE = 0x0200
    Local $i = 0
    if $handle = 1 Then
        Local $winhandle = $Window
    Elseif $handle = 0 Then
        Local $winhandle = WinGetHandle($Window)
    EndIf
    
    If $X = "" Or $Y = "" Then
;~         MsgBox(32, "KCH: Problem", "_MouseMovePlus() called with bad number of params?")
        Return
    EndIf
    
    DllCall("user32.dll", "int", "SendMessage", _
            "hwnd", $winhandle, _
            "int", $WM_MOUSEMOVE, _
            "int", 0, _
            "long", _MakeLong($X, $Y)) 
EndFunc   ;==>_MouseMoveMinimized

Func _MakeLong($LoWord, $HiWord)
    Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc   ;==>_MakeLong
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...