Jump to content

Recommended Posts

Original posted by CoePSX

 

Spoiler

#include <GUIConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <Color.au3>
#include <WinAPI.au3>

Global $HotKeyDraw = "{1}"
Global $HotKeyPause = "{2}"
Global $HotKeyNew = "{3}"
Global $HotKeyQuit = "{ESC}"
Global $TrayTip = "[1]-Draw [2]-Pause [3]-New [ESC]-Quit"
Global $Tip = "Draw-[1]       Pause-  [2] New- [3]        Quit-[ESC]";;Alt+0160;;

Global $Mousebuffer = 10
Global $DrawCompleted = @ScriptDir & "\Audio\Tada.wav"
Global $Error = @ScriptDir & "\Audio\Error.wav"

Global $threshold
Global $image
Global $width
Global $height
Global $pixels
Global $pathString = "12345678"
Global $scramble = False
Global $rotate = 0
Global $speed

;; Check hotkeys ;;
If (Not HotKeySet ($HotKeyDraw, "Nothing")) Then
    SoundPlay($Error, 1)    ;;MsgBox (16, "Error", "Could not register the F11 hotkey.");;
    Exit
EndIf
If (Not HotKeySet ($HotKeyNew, "Nothing")) Then
    SoundPlay($Error, 1)
    Exit
EndIf
If (Not HotKeySet ($HotKeyQuit, "Nothing")) Then
    SoundPlay($Error, 1)
    Exit
EndIf

;; Image dialog ;;
$imageFile = FileOpenDialog ("Open image", @WorkingDir, "Images (*.jpg;*.jpeg;*.gif;*.bmp)", 1)
If (@error) Then Exit


;; Options dialog ;;
$optGUI = GUICreate ("Settings", 160, 300, -1, -1, $WS_CAPTION, BitOr ($WS_EX_APPWINDOW, $WS_EX_TOOLWINDOW))
GUICtrlCreateGroup ("Image processing", 5, 5, 150, 85)
GUICtrlCreateLabel ("Sensitivity (0~255):", 10, 28, 110, 15)
$thresholdInput = GUICtrlCreateInput ("140", 120, 25, 25, 20, $ES_NUMBER)
GUICtrlCreateLabel ("Width (px):", 10, 48, 110, 15)
$widthInput = GUICtrlCreateInput ("100", 120, 45, 30, 20, $ES_NUMBER)
GUICtrlCreateLabel ("Height (px):", 10, 68, 110, 15)
$heightInput = GUICtrlCreateInput ("100", 120, 65, 30, 20, $ES_NUMBER)
GUICtrlCreateGroup ("Drawing pattern", 5, 95, 150, 140)
$horizontalRadio = GUICtrlCreateRadio ("Horizontal", 10, 115, 110, 15)
$verticalRadio = GUICtrlCreateRadio ("Vertical", 10, 135, 110, 15)
$diagonalRadio = GUICtrlCreateRadio ("Diagonal", 10, 155, 110, 15)
$rotateRadio = GUICtrlCreateRadio ("Spiral", 10, 175, 110, 15)
$scrambleRadio = GUICtrlCreateRadio ("Random", 10, 195, 110, 15)
GUICtrlSetState ($scrambleRadio, $GUI_CHECKED)
GUICtrlCreateLabel ("Mouse speed (0~100):", 10, 213, 110, 15)
$speedInput = GUICtrlCreateInput ("1", 120, 210, 25, 20, $ES_NUMBER)
$okBtn = GUICtrlCreateButton ("OK", 30, 275, 30, 20)
$cancelBtn = GUICtrlCreateButton ("Close", 80, 275, 50, 20)
GUISetState ()
GUICtrlCreateLabel($Tip, 20, 240 ,120, 35, $SS_CENTER)
GUICtrlSetColor(-1,0xFF0000)

While 1
    Switch (GUIGetMsg ())
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cancelBtn
            Exit
        Case $okBtn
            $threshold = GUICtrlRead ($thresholdInput)
            $width = GUICtrlRead ($widthInput)
            $height = GUICtrlRead ($heightInput)
            $speed = GUICtrlRead ($speedInput)
            If    (GUICtrlRead ($horizontalRadio) == $GUI_CHECKED) Then
                $pathString = "45273618"
            ElseIf (GUICtrlRead ($verticalRadio) == $GUI_CHECKED) Then
                $pathString = "27453618"
            ElseIf (GUICtrlRead ($diagonalRadio) == $GUI_CHECKED) Then
                $pathString = "36184527"
            ElseIf (GUICtrlRead ($rotateRadio) == $GUI_CHECKED) Then
                $pathString = "14678532"
                $rotate = 1
            ElseIf (GUICtrlRead ($scrambleRadio) == $GUI_CHECKED) Then
                $scramble = True
            EndIf

            GUIDelete ($optGUI)
            ExitLoop
    EndSwitch
WEnd


;; Processing dialog ;;
$GUI = GUICreate ("Processing image...", $width, $height + 20, -1, -1, $WS_CAPTION, BitOr ($WS_EX_APPWINDOW, $WS_EX_TOOLWINDOW))
GUISetBkColor (0xffffff)
$imageBox = GUICtrlCreatePic ($imageFile, 0, 0, $width, $height)
$progress = GUICtrlCreateProgress (0, $height, $width, 20)
GUISetState ()

;; Get image pixels ;;
$dc = _WinAPI_GetDC ($GUI)
$memDc = _WinAPI_CreateCompatibleDC ($dc)
$bitmap = _WinAPI_CreateCompatibleBitmap ($dc, $width, $height)
_WinAPI_SelectObject ($memDc, $bitmap)
_WinAPI_BitBlt ($memDc, 0, 0, $width, $height, $dc, 0, 0, $SRCCOPY)
$bits = DllStructCreate ("dword[" & ($width * $height) & "]")
DllCall ("gdi32", "int", "GetBitmapBits", "ptr", $bitmap, "int", ($width * $height * 4), "ptr", DllStructGetPtr ($bits))
GUICtrlDelete ($imageBox)

;; Process the pixels ;;
Dim $pixels[$width][$height]
For $y = 0 To ($height - 1)
    For $x = 0 To ($width - 1)
        $index = ($y * $width) + $x
        $color = DllStructGetData ($bits, 1, $index)

        $red = _ColorGetBlue ($color)
        $green = _ColorGetGreen ($color)
        $blue = _ColorGetRed ($color)
        $shade = ($red + $green + $blue) / 3
        If ($shade > $threshold) Then
            $color = 0xffffff
            $pixels[$x][$y] = 0
        Else
            $color = 0
            $pixels[$x][$y] = 1
        EndIf

        DllStructSetData ($bits, 1, $color, $index)
    Next

    DllCall ("gdi32", "int", "SetBitmapBits", "ptr", $bitmap, "int", ($width * $height * 4), "ptr", DllStructGetPtr ($bits))
    _WinAPI_BitBlt ($dc, 0, 0, $width, $height, $memDc, 0, 0, $SRCCOPY)
    GUICtrlSetData ($progress, ($y * 100) / $height)
Next

_WinAPI_ReleaseDC ($GUI, $dc)
GUIRegisterMsg ($WM_PAINT, "OnPaint")


;; Ready to draw ;;
TrayTip ("Ready!", $TrayTip, 10)
HotKeySet ($HotKeyDraw, "Draw")
HotKeySet ($HotKeyNew, "New")
HotKeySet ($HotKeyQuit, "Quit")
HotKeySet ($HotKeyPause, "_TimeOut")


While 1
    Sleep (60000)
WEnd


Func OnPaint ($hwndGUI, $msgID, $wParam, $lParam)
    Local $paintStruct = DllStructCreate ("hwnd hdc;int fErase;dword rcPaint[4];int fRestore;int fIncUpdate;byte rgbReserved[32]")

    $dc = DllCall ("user32", "hwnd", "BeginPaint", "hwnd", $hwndGUI, "ptr", DllStructGetPtr ($paintStruct))
    $dc = $dc[0]

    _WinAPI_BitBlt ($dc, 0, 0, $width, $height, $memDc, 0, 0, $SRCCOPY)

    DllCall ("user32", "hwnd", "EndPaint", "hwnd", $hwndGUI, "ptr", DllStructGetPtr ($paintStruct))
    Return $GUI_RUNDEFMSG
EndFunc


Func Draw ()
    $mouseCenter = MouseGetPos ()
    $x0 = $mouseCenter[0] - ($width / 2)
    $y0 = $mouseCenter[1] - ($height / 2)

    ;; Move the mouse around the drawing perimeter ;;
    MouseMove ($x0, $y0)
    MouseMove ($x0 + $width, $y0)
    MouseMove ($x0 + $width, $y0 + $height)
    MouseMove ($x0, $y0 + $height)
    MouseMove ($x0, $y0)

    ;; Draw all the areas ;;
    $stack = CreateStack (1000)
    For $y = 0 To ($height - 1)
        For $x = 0 To ($width - 1)
            If ($pixels[$x][$y] == 1) Then
                MouseMove ($x + $x0, $y + $y0, $speed)
                MouseDown ("primary")
                DrawArea ($stack, $x, $y, $x0, $y0)
                Sleep (10)
                MouseUp ("primary")
                MouseUp ("primary")
                MouseUp ("primary")
                Sleep ($Mousebuffer)
            Else
            EndIf
        Next
    Next

    ;; Reset the pixels statuses ;;
    For $y = 0 To ($height - 1) Step 1
        For $x = 0 To ($width - 1) Step 1
            If ($pixels[$x][$y] == 2) Then
                $pixels[$x][$y] = 1
            EndIf
        Next
    Next
    SoundPlay($DrawCompleted, 1)
EndFunc


Func DrawArea (ByRef $stack, $x, $y, $x0, $y0)
    Local $path[8]
    Local $continue

    $path = MakePath ($pathString)

    While 1
        MouseMove ($x + $x0, $y + $y0, $speed)
        $pixels[$x][$y] = 2

        If ($scramble) Then ScramblePath ($path)
        If ($rotate > 0) Then RotatePath ($path, $rotate)

        ;;;;;;;;;;;;;;;;;;;
        ;; +---+---+---+ ;;
        ;; | 1 | 2 | 3 | ;;
        ;; +---+---+---+ ;;
        ;; | 4 |   | 5 | ;;
        ;; +---+---+---+ ;;
        ;; | 6 | 7 | 8 | ;;
        ;; +---+---+---+ ;;
        ;;;;;;;;;;;;;;;;;;;

        $continue = False
        For $i = 0 To 7
            Switch ($path[$i])
                Case 1
                    If (($x > 0) And ($y > 0)) Then
                        If ($pixels[$x - 1][$y - 1] == 1) Then
                            Push ($stack, $x, $y)
                            $x -= 1
                            $y -= 1
                            $continue = True
                            ExitLoop
                        EndIf
                    EndIf

                Case 2
                    If ($y > 0) Then
                        If ($pixels[$x][$y - 1] == 1) Then
                            Push ($stack, $x, $y)
                            $y -= 1
                            $continue = True
                            ExitLoop
                        EndIf
                    EndIf

                Case 3
                    If (($x > 0) And ($y < 0)) Then
                        If ($pixels[$x + 1][$y - 1] == 1) Then
                            Push ($stack, $x, $y)
                            $x += 1
                            $y -= 1
                            $continue = True
                            ExitLoop
                        EndIf
                    EndIf

                Case 4
                    If ($x > 0) Then
                        If ($pixels[$x - 1][$y] == 1) Then
                            Push ($stack, $x, $y)
                            $x -= 1
                            $continue = True
                            ExitLoop
                        EndIf
                    EndIf

                Case 5
                    If ($x < ($width - 1)) Then
                        If ($pixels[$x + 1][$y] == 1) Then
                            Push ($stack, $x, $y)
                            $x += 1
                            $continue = True
                            ExitLoop
                        EndIf
                    EndIf

                Case 6
                    If (($x < 0) And ($y > 0)) Then
                        If ($pixels[$x - 1][$y + 1] == 1) Then
                            Push ($stack, $x, $y)
                            $x -= 1
                            $y += 1
                            $continue = True
                            ExitLoop
                        EndIf
                    EndIf

                Case 7
                    If ($y < ($height - 1)) Then
                        If ($pixels[$x][$y + 1] == 1) Then
                            Push ($stack, $x, $y)
                            $y += 1
                            $continue = True
                            ExitLoop
                        EndIf
                    EndIf

                Case 8
                    If (($x < ($width - 1)) And ($y < ($height - 1))) Then
                        If ($pixels[$x + 1][$y + 1] == 1) Then
                            Push ($stack, $x, $y)
                            $x += 1
                            $y += 1
                            $continue = True
                            ExitLoop
                        EndIf
                    EndIf
            EndSwitch
        Next
        If ($continue) Then ContinueLoop

        If (Not Pop ($stack, $x, $y)) Then ExitLoop
    WEnd
EndFunc

Func MakePath ($string)
    Return StringSplit ($string, "")
EndFunc


Func ScramblePath (ByRef $path)
    Local $table = "12345678"
    Local $newPath[8]

    For $i = 8 To 1 Step -1
        $next = StringMid ($table, Random (1, $i, 1), 1)
        $newPath[$i - 1] = Number ($next)
        $table = StringReplace ($table, $next, "")
    Next

    $path = $newPath
EndFunc


Func RotatePath (Byref $path, $places)
    If ($places == 0) Then
        Return $path
    Else
        For $i = 1 To Abs ($places)
            $temp = $path[7]
            $path[7] = $path[6]
            $path[6] = $path[5]
            $path[5] = $path[4]
            $path[4] = $path[3]
            $path[3] = $path[2]
            $path[2] = $path[1]
            $path[1] = $path[0]
            $path[0] = $temp
        Next
    EndIf
EndFunc

Func CreateStack ($size)
    Dim $stack[$size + 1][2]
    $stack[0][0] = 0
    $stack[0][1] = $size
    Return $stack
EndFunc


Func Push (ByRef $stack, $x, $y)
    $stack[0][0] += 1
    If ($stack[0][0] > $stack[0][1]) Then
        $stack[0][1] += 1000
        ReDim $stack[$stack[0][1] + 1][2]
    EndIf

    $stack[$stack[0][0]][0] = $x
    $stack[$stack[0][0]][1] = $y
EndFunc


Func Pop (ByRef $stack, ByRef $x, ByRef $y)
    If ($stack[0][0] < 1) Then
        Return False
    EndIf

    $x = $stack[$stack[0][0]][0]
    $y = $stack[$stack[0][0]][1]

    $stack[0][0] -= 1
    Return True
EndFunc


Func Nothing ()
EndFunc

Func _TimeOut()
    If Not IsDeclared("isPaused") Then Global $isPaused = False
    $isPaused = Not $isPaused
    Mouseup ("primary")   
   While $isPaused
        Sleep(250)
    Wend
    Mousedown ("primary")
EndFunc

Func New ()
    MouseUp ("primary")
    If @Compiled = 1 Then
        Run( FileGetShortName(@ScriptFullPath))
    Else
        Run( FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath))
    EndIf
    Exit
EndFunc

Func Quit ()
    MouseUp ("primary")
    Exit
EndFunc

 

 

 

Drawing_Script.au3

Edited by v120
Update
Link to post
Share on other sites
  • 2 years later...
  • Moderators
Posted (edited)

lunapari455,

Downloads fine for me.

M23

Edit: And the spoiler holds the code too.

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Sachs
      I have a few questions:
      BACKGROUND
      I am using Oracle Application Testing Suite's OpenScript 13 (Eclipse IDE), Oracle Java 6, and AutoIt.
      My goal is to access a given Internet Explorer browser window (`$ieTitle`), send the keystroke of "shift-control-s" for "Save As" functionality to be invoked, so that I can download a (PDF) file to a given location ($fileName).
      The code within the script `DownloadPdfFile.au3` is
      $ieTitle = $CmdLine[1] $ieControl = "AVL_AVView31" $fileName = $CmdLine[2] ControlFocus($ieTitle, "", $ieControl) ControlSend($ieTitle, "", $ieControl, "+^s") ; Save as dialog $winTitle = "Save As" ; wait for Save As window WinWait($winTitle) ; activate Save As window If Not WinActive($winTitle) Then WinActivate($winTitle) ControlFocus($winTitle,"","Edit1") ControlSetText($winTitle,"","Edit1",$fileName) Sleep(2000) ControlClick($winTitle,"","Button3") Exit 0 So I compiled it with SciTE-Lite (32-bit Version 4.4.6 , creating `DownloadPdfFile.exe`, and so within my Java code, I have
      String command = autoItExePath + " " + scriptPath + " \"" + winTitle + "\" " + directoryPath.toFile().toString() + "\\Form9Report" + sdf_ddmmmyyyy.format(new Date()) + ".pdf"; try { Process process = Runtime.getRuntime().exec(command); process.waitFor(); } catch (Exception e) { logger.error("Exception " + e.getMessage(), e); } The output would be like `C:\Program Files (x86)\AutoIt3\AutoIt3.exe C:\...\AutoItScripts\DownloadPdfFile.au3 "https://****.com/****.exe?temp_id=**** - Internet Explorer" C:\...\Report05Apr2022.pdf"` which does run without the $cmdLine successfully. 
      When executed by Java, I see in the taskbar an icon, which I right-click has "[Check] Script Paused" and "Exit".
      Questions:
      (1) How do I unpause the script?
      (2) How do I avoid having the script paused?
      Any help is appreciated.
    • By asiawatcher
      hi below i got one script i made which runs audacity starts a recording and ends it at specific times
       
      when i run the script even if it isn't the time to start audacity and sits idle on taskbar the pc fan gets very loud, when i close the script it comes back to normal 
       
      why this happens ? anything wrong with my code ?? cheers
      #include <INet.au3> #include <Array.au3> #include <WinAPIFiles.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <string.au3> #include <FTPEx.au3> #include <ClipBoard.au3> #include <date.au3> #include <ProgressConstants.au3> #include <IE.au3> #Include <Constants.au3> #Include <INET.au3> #include <SendMessage.au3> #include <File.au3> #include <String.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Misc.au3> #include <FileConstants.au3> #include <WinAPI.au3> while 1 if @HOUR = '11' And @MIN = '00' Then  Run("C:\Program Files (x86)\Audacity\audacity.exe", "", @SW_MAXIMIZE) SLEEP(2000) if ProcessExists("audacity.exe") Then winactivate("Audacity") EndIf      Send("r") ;;KREVATI Sleep(1000 * 60) endif if @HOUR = '23' And @MIN = '00' Then  if ProcessExists("audacity.exe") Then winactivate("Audacity") EndIf Send("s") Sleep(1000 * 60) EndIf wend  
    • By badcoder123
      Hey, All!
       
      I was looking into the help file at all the drawing utilities and I was wondering if you draw a translucent line that follows your cursor. Upon looking for ideas I came across this thread (1.0) and saw UEZ's response. I also came across another post that UEZ replied to and found this reply (1.1) where he shows how you can draw on the desktop. This is what I'm looking for however I'd still like to be able to interact with a designated application and have the line/curve/vector passively follow it. Obviously we don't move our cursor very linearly so it would have to be able to draw on vectors. Am I over complicating this? 
      Any ideas or starting points I should look more into? 
       
       
       
      1.0
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global Const $aFullScreen = WinGetPos(WinGetHandle("[TITLE:Program Manager;CLASS:Progman]")) Global $iHeight = 4 Global Const $hGUI = GUICreate("Screen Ruler Underline for free :-)", $aFullScreen[2], $iHeight, $aFullScreen[0], MouseGetPos(1), $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TRANSPARENT)) GUISetBkColor(0x000000) WinSetTrans($hGUI, "", 0xA0) GUISetState() HotKeySet("{ESC}", "_Exit") Do WinMove($hGUI, "", $aFullScreen[0], MouseGetPos(1)) Until Not Sleep(50) Func _Exit() GUIDelete() Exit EndFunc _____________
      1.1
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> AutoItSetOption("GUIOnEventMode", 1) Global $hGUI, $hDC, $hPen, $obj_orig $hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP) WinSetTrans($hGUI, "", 1) GUISetState() _line() Func _line() $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop) $hPen = _WinAPI_CreatePen($PS_SOLID, 2, 0x00ff) $obj_orig = _WinAPI_SelectObject($hDC, $hPen) GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Draw", $hGUI) GUISetOnEvent(-3, "_Exit") Do Until Not Sleep(1000) EndFunc ;==>_line Func Draw() Local $aMC, $mxo, $myo $aMC = GUIGetCursorInfo($hGUI) Do GUISetCursor(0, 1, 0) $mxo = $aMC[0] $myo = $aMC[1] $aMC = GUIGetCursorInfo($hGUI) If $mxo <> $aMC[0] Or $myo <> $aMC[1] Then _WinAPI_DrawLine($hDC, $aMC[0], $aMC[1], $mxo, $myo) _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE) $mxo = $aMC[0] $myo = $aMC[1] EndIf Sleep(10) Until Not $aMC[2] EndFunc Func _Exit() _WinAPI_SelectObject($hDC, $obj_orig) _WinAPI_DeleteObject($hPen) _WinAPI_ReleaseDC(0, $hDC) Exit EndFunc  
    • By ademon
      Hi. I can open the editor with out problems but I can not compile because it is placed on another partition diferent from C.
      Can you provide an update of this bug?


×
×
  • Create New...