Jump to content
Sign in to follow this  
CyNDeR

Weird problem with script. (Fixed)

Recommended Posts

CyNDeR

This is a functional script that reproduces the error:

HotKeySet("{ESC}", "End")
Run("mspaint.exe")
WinWaitActive("[CLASS:MSPaintApp]")
WinSetState("[CLASS:MSPaintApp]", "", @SW_MINIMIZE)
Opt("MouseCoordMode", 2)
Setup()
While 1
    Lines()
WEnd
Func Setup()
    ControlClick("[CLASS:MSPaintApp]", "", 59415, "left", 1, 43, 42)
    ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 41, 15)
    ControlClick("[CLASS:MSPaintApp]", "", "[CLASS:Afx:1000000:8]")
EndFunc   ;==>Setup
Func Lines()
    $Size = ControlGetPos("[CLASS:MSPaintApp]", "", "[CLASS:Afx:1000000:8]")
    $Rnd = Random(1, 15)
    For $i = 1 To $Rnd
        $WindowState = WinGetState("[CLASS:MSPaintApp]")
        If BitAND($WindowState, 8) Then
            ControlClick("[CLASS:MSPaintApp]", "", 59415, "left", 1, 16, 141)
            PickColor()
            PickLineType()
            $X1 = Random($Size[0] + 5, $Size[0] + $Size[2] - 5, 1)
            $Y1 = Random($Size[1] + 5, $Size[1] + $Size[3] - 5, 1)
            $X2 = Random($Size[0] + 5, $Size[0] + $Size[2] - 5, 1)
            $Y2 = Random($Size[1] + 5, $Size[1] + $Size[3] - 5, 1)
            MouseClickDrag("left", $X1, $Y1, $X2, $Y2, 2)
        EndIf
    Next
EndFunc   ;==>Lines
Func PickColor()
    $color = Random(1, 28, 1)
    Switch $color
        Case 1
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 41, 15)
        Case 2
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 56, 15)
        Case 3
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 72, 15)
        Case 4
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 88, 15)
        Case 5
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 104, 15)
        Case 6
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 120, 15)
        Case 7
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 136, 15)
        Case 8
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 152, 15)
        Case 9
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 169, 15)
        Case 10
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 185, 15)
        Case 11
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 200, 15)
        Case 12
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 216, 15)
        Case 13
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 232, 15)
        Case 14
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 248, 15)
        Case 15
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 41, 32)
        Case 16
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 56, 32)
        Case 17
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 72, 32)
        Case 18
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 88, 32)
        Case 19
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 104, 32)
        Case 20
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 120, 32)
        Case 21
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 136, 32)
        Case 22
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 152, 32)
        Case 23
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 169, 32)
        Case 24
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 185, 32)
        Case 25
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 200, 32)
        Case 26
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 216, 32)
        Case 27
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 232, 32)
        Case 28
            ControlClick("[CLASS:MSPaintApp]", "", 59416, "left", 1, 248, 32)
    EndSwitch
EndFunc   ;==>PickColor
Func PickLineType()
    $LineType = Random(1, 5, 1)
    Switch $LineType
        Case 1
            ControlClick("[CLASS:MSPaintApp]", "", 59415, "left", 1, 28, 219)
        Case 2
            ControlClick("[CLASS:MSPaintApp]", "", 59415, "left", 1, 28, 230)
        Case 3
            ControlClick("[CLASS:MSPaintApp]", "", 59415, "left", 1, 28, 241)
        Case 4
            ControlClick("[CLASS:MSPaintApp]", "", 59415, "left", 1, 28, 254)
        Case 5
            ControlClick("[CLASS:MSPaintApp]", "", 59415, "left", 1, 28, 281)
    EndSwitch
EndFunc   ;==>PickLineType
Func End()
    Exit
EndFunc   ;==>End

The problem i'm having is that after it runs for a bit, it moves the ToolBox to a diffrent position. I've tried using numerous delays and such but it still does it. Any ideas?

EDIT: Fixed it. I was off a few pixels on one of the coords.

Edited by CyNDeR

My scripts: Random Painter

Share this post


Link to post
Share on other sites
zfisherdrums

Hello CyNDeR,

I noticed that MS Paint will undock the toolbar if you double click-and-drag the line-width selection panel. I believe what may be happening is the ControlClick calls are happening so quickly between lines 21, PickColor(), and PickLineType() that it is producing this effect.

When I placed a small sleep statement (i.e. "Sleep( 10 )" ) after PickLineType(), the script did not appear to exhibit this behavior.

Zach...

PS: The default drawing area will always be set to the size used in the last session. Mine was smaller than the algorithm accounted for. I found the registry keys that reflected the width and height of the drawing area. I added these inside the "Lines()" function like so:

Func Lines()
    $Size = ControlGetPos("[CLASS:MSPaintApp]", "", "[CLASS:Afx:1000000:8]")
    $width = RegRead( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Paint\View", "BMPWidth" )
    $height = RegRead( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Paint\View", "BMPHeight" )
    $Rnd = Random(1, 15)
    For $i = 1 To $Rnd
        $WindowState = WinGetState("[CLASS:MSPaintApp]")
        If BitAND($WindowState, 8) Then
            ControlClick("[CLASS:MSPaintApp]", "", 59415, "left", 1, 16, 141)
            PickColor()
            PickLineType()
            Sleep(10)
            $X1 = Random($Size[0] + 5, $Size[0] + $width - 5, 1)
            $Y1 = Random($Size[1] + 5, $Size[1] + $height - 5, 1)
            $X2 = Random($Size[0] + 5, $Size[0] + $width - 5, 1)
            $Y2 = Random($Size[1] + 5, $Size[1] + $height - 5, 1)
            MouseClickDrag("left", $X1, $Y1, $X2, $Y2, 2)           
        EndIf
    Next
EndFunc ;==>Lines

The declarations of $width and $height should technically be outside the function as the drawing area "shouldn't" change during your script. But I leave that to your discretion.

I really enjoyed reading through your code!

Zach...

EDIT: Ooops! My bad...did not see that you already fixed it.

Edited by zfisherdrums

Share this post


Link to post
Share on other sites
CyNDeR

Hello CyNDeR,

I noticed that MS Paint will undock the toolbar if you double click-and-drag the line-width selection panel. I believe what may be happening is the ControlClick calls are happening so quickly between lines 21, PickColor(), and PickLineType() that it is producing this effect.

When I placed a small sleep statement (i.e. "Sleep( 10 )" ) after PickLineType(), the script did not appear to exhibit this behavior.

Zach...

PS: The default drawing area will always be set to the size used in the last session. Mine was smaller than the algorithm accounted for. I found the registry keys that reflected the width and height of the drawing area. I added these inside the "Lines()" function like so:

Func Lines()
    $Size = ControlGetPos("[CLASS:MSPaintApp]", "", "[CLASS:Afx:1000000:8]")
    $width = RegRead( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Paint\View", "BMPWidth" )
    $height = RegRead( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Paint\View", "BMPHeight" )
    $Rnd = Random(1, 15)
    For $i = 1 To $Rnd
        $WindowState = WinGetState("[CLASS:MSPaintApp]")
        If BitAND($WindowState, 8) Then
            ControlClick("[CLASS:MSPaintApp]", "", 59415, "left", 1, 16, 141)
            PickColor()
            PickLineType()
            Sleep(10)
            $X1 = Random($Size[0] + 5, $Size[0] + $width - 5, 1)
            $Y1 = Random($Size[1] + 5, $Size[1] + $height - 5, 1)
            $X2 = Random($Size[0] + 5, $Size[0] + $width - 5, 1)
            $Y2 = Random($Size[1] + 5, $Size[1] + $height - 5, 1)
            MouseClickDrag("left", $X1, $Y1, $X2, $Y2, 2)           
        EndIf
    Next
EndFunc;==>Lines

The declarations of $width and $height should technically be outside the function as the drawing area "shouldn't" change during your script. But I leave that to your discretion.

I really enjoyed reading through your code!

Zach...

EDIT: Ooops! My bad...did not see that you already fixed it.

I didnt even think about the height and width being stored in the registry, thats an awesome idea. I'm putting it in the script right now. As for the problem i was having, one of the coords was wrong and it clicked the wrong place as to move the panel. I'll be posting the updated script in just a sec. You can find the link to the full script in my sig. Thanks alot!

My scripts: Random Painter

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  

×