Jump to content

Paint autoit script


oOo
 Share

Recommended Posts

Hello,

I began to write autoit script for one month now.

What I want to do now with autoit is "abstract art" using the software paint (Let me explain myself before going back ;p)

The script has for now all the tools position saved. His work is to use them randomly on the blank window. It works perfectly and eventually makes beautiful things (but not often).

My first easy problem is that while the script is running I have windows which pop ups (like avast, publicity, etc) and then paint is no more active so the script is no more drawing. Do you know a function which i could use every 10 minutes for example to set the paint window active again?

My second harder problem is that while the script is running, I can no more use my computer. The mouse is moving from one tool to the other, clicking on the white paper, dragging colors, etc.. Is there a way to have the script work with "a virtual mouse" on "a virtual computer"so that i can still use my computer (or is there any way to solve this problem :s?).

Thanks

Shravan

Link to comment
Share on other sites

http://www.autoitscript.com/autoit3/docs/functions/WinActivate.htm

http://www.autoitscript.com/autoit3/docs/functions/WinActive.htm

The above 2 commands can be used to make it active, simply have it run every 10 minutes or so, as far as a virtual mouse, I dont think so however some programs have been able to "mouse a mouse over coordinates on a certain process" without using the real mouse however i am not familiar with this or sure if autoit is even capable of this.

Link to comment
Share on other sites

Complicated? Not at all!

I just saved the position of the basic paint tools in an array.

Then I have a function which randomly chose color and tool and then during 15 seconds i make it randomly move on the white paper.

Easy, ... and useless I know but I wanted to see what would be the paint like after 1 hour ;p

Link to comment
Share on other sites

You can use these funcs to click on minimised paint.

It works just like MouseClick, only diference is first parameter must be window title and no parameter for speed at the end.

Func _MouseClickMinimized($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 = "right"
            $Button = $MK_RBUTTON
            $ButtonDown = $WM_RBUTTONDOWN
            $ButtonUp = $WM_RBUTTONUP
        Case $Button = "left"
            $Button = $MK_LBUTTON
            $ButtonDown = $WM_LBUTTONDOWN
            $ButtonUp = $WM_LBUTTONUP
        Case Else
            Exit
    EndSelect
    If $X = "" Or $Y = "" Then
        Exit
    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   ;==>_MouseClickMinimized

Func _MouseMoveMinimized($Window, $X = "", $Y = "")
    Local $WM_MOUSEMOVE = 0x0200
    Local $i = 0

    If $X = "" Or $Y = "" Then
        Exit
    EndIf

    DllCall("user32.dll", "int", "SendMessage", _
            "hwnd", WinGetHandle($Window), _
            "int", $WM_MOUSEMOVE, _
            "int", 0, _
            "long", _MakeLong($X, $Y))
EndFunc   ;==>_MouseMoveMinimized

Func _SendMinimized($Window, $keys)
    ControlSend($Window, "", "", $keys)
EndFunc   ;==>_SendMinimized

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

make sure you add

Opt("MouseCoordMode", 2)        ;1=absolute, 0=relative, 2=client
at the beginning of your script

here's what i have done with paint:

http://autoit.pri.ee/pildid/AutoitPaint2.png

http://autoit.pri.ee/da/omnimon/

Edited by E1M1

edited

Link to comment
Share on other sites

To E1M1 : Thank you I have understood all of it. There is no way I could have figured it alone as i didn't know any of these functions you use like DllCall or ControlSend.. Did you write these functions (_MouseMoveMinimized,_MouseClickMinimized, etc..) right now while answering to my questions ( oO ) or is there somewhere some tutorial about it?

To Synct : I'll send some screenshot to you by private message if you want.

Edited by oOo
Link to comment
Share on other sites

@Synct pic is pure math + random. Image you see in video is generated from image fusing following function.

Func PixelRecursive($x, $y, $w, $h, $c, $s)
    Local $data = ""
    $start = PixelSearch($x, $y, $w, $h, $c, $s)
    $data &= 'MouseClick("left", $XOffset+' & $start[0] & ',$YOffset+' & $start[1] & ',1,0)' & @CRLF
    If Not @error Then
        For $i = $start[1] To $h
            For $n = $x To $w
                $xy = PixelSearch($n, $i, $w, $i + 1, $c, $s)
                If Not @error Then
                    $n = $xy[0]
                    $data &= 'MouseClick("left",$XOffset+' & $xy[0] & ',$YOffset+' & $xy[1] & ',1,0)' & @CRLF
                EndIf
                ToolTip($i & " " & $n , 1000,100)
            Next
        Next
        ClipPut($data)
    EndIf
EndFunc   ;==>PixelRecursive

Diferently from PixelSearch which returns only first found pixel it gets you all pixels found in given area.

Here's link to generated paint script. http://autoit.pri.ee/da/test.zip

Edited by E1M1

edited

Link to comment
Share on other sites

Ok Just now, I have tried using your function _MouseClickMinimized in a test script and couldn't make it work. Apparently I haven't understood fully how you do it because I have been thinking about it for 20-30 minutes without beeing able to correct it :s

Here is what I am doing.

All my scripts are in a folder called "Informatique" (I'am french sorry ;p). So when I am inside the folder, the name of the window is "Informatique" (It is written on the top of it..). I minimize the window and then run the test script which is only supposed to click on the red cross to close the window.

I know the exact size of my window and the exact place of the red cross.

So I write in the test script this : _MouseClickMinimized("Informatique", "left", XredCross, YredCross, 1) and... nothing happens :/

I tried measuring X and Y from the top left of my screen and then from the top left of the window but nothing happens. I thought that maybe you (or I) had interverted the X and the Y but it is still not this.

I am still searching on my own but if you see what is the problem please tell me.

EDIT : Of course I didn't forget this line : Opt("MouseCoordMode", 2)

Edited by oOo
Link to comment
Share on other sites

Ok here it is :

Opt("MouseCoordMode", 2)

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

Func _MouseClickMinimized($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 = "right"
            $Button = $MK_RBUTTON
            $ButtonDown = $WM_RBUTTONDOWN
            $ButtonUp = $WM_RBUTTONUP
        Case $Button = "left"
            $Button = $MK_LBUTTON
            $ButtonDown = $WM_LBUTTONDOWN
            $ButtonUp = $WM_LBUTTONUP
        Case Else
            Exit
    EndSelect
    If $X = "" Or $Y = "" Then
        Exit
    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   ;==>_MouseClickMinimized





_MouseClickMinimized("Informatique", "left", 785, 15, 1)
Link to comment
Share on other sites

That's strange. It works with game but doesn work with paint....

Here's what I made for paint.

#include <process.au3>

Opt("MouseClickDelay", 0)      ;10 milliseconds
Opt("MouseClickDownDelay", 0)  ;10 milliseconds

Func _ProcessGetWindow($PId)
    If IsNumber($PId) = 0 Or ProcessExists(_ProcessGetName($PId)) = 0 Then
        SetError(1)
    Else
        Local $WinList = WinList()
        Local $i = 1
        Local $WindowHandle = ""
        While $i <= $WinList[0][0] And $WindowHandle = ""
            If WinGetProcess($WinList[$i][0], "") = $PId Then
                $WindowHandle = $WinList[$i][1]
            Else
                $i += 1
            EndIf
        WEnd
        Return $WindowHandle
    EndIf
EndFunc   ;==>_ProcessGetWindow

$hWnd = _ProcessGetWindow(ProcessExists("mspaint.exe"))
$str = StringSplit(WinGetClassList ( $hWnd),@LF)
For $i = 1 To $str[0]
    If stringinstr($str[$i],"000000") Then
        $str = $str[$i]
        ExitLoop
    EndIf
Next

;Our painting starts here!!!
for $i = 1 To 100
ControlClick ($hWnd, "", "[CLASS:"&$str&";]", "left", 1, $i,$i)
Next

If you wanna boost speed you can split ur image between some scripts and then run multiple compiled exes at once. for some reason it turns unstable if you don't have sleep(1) after click. but with sleep(1) it's times slower than normal mouseclick()

Edited by E1M1

edited

Link to comment
Share on other sites

Thanks I'll try it right now. (Paint apparently hides some things from us ;))

EDIT : This works. Thank you very much you gave me the solution to the problem I was trying to solve since I began working with autoit :)

Edited by oOo
Link to comment
Share on other sites

Art work? The only things I made yet are worse than kid drawing right now >< But I am so happy that everything is working ;p

From what you shown me in your other answer i will try to do some real art now. I'll search for tutorials/info/moreExamples now.

See ya

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...