Jump to content

Recommended Posts

Hi I'm working on script which should save positions into $pos[] and then call them all back in _Replay function. Sadly it works just for last saved position.

 

#include <Misc.au3>
Local $hDLL = DllOpen("user32.dll")

HotKeySet('p', '_Replay')

Local $log
Local $i = 0
Local $pos[($i)]
Local $var = 0

_Rec()

Func _Rec()
    While 1
        If _IsPressed("01", $hDLL) Then ;MouseRec
            Global $pos[($i + 2)]
            $pos[($var)] = MouseGetPos(0)
            $var += 1
            $pos[($var)] = MouseGetPos(1)
            ConsoleWrite('$pos[' & $var - 1 & ']: ' & $pos[$var - 1] & ', $pos[' & $var & ']: ' & $pos[$var] & @CRLF)
            $var += 1
            $i += 2
            $log = $i / 2

            While _IsPressed("01", $hDLL) ;Wait for release
                Sleep(50)
            WEnd
        EndIf

        ConsoleWrite('Saved mouse positions: ' & ($i / 2) & @CRLF)
        Sleep(100)

    WEnd
EndFunc   ;==>_Rec

Func _Replay()
    Local $c0 = 0
    Local $c1 = 1

    For $count = 1 To $log Step 1
        MouseMove($pos[$c0], $pos[$c1])
        ConsoleWrite('REPLAY:  ' & $pos[$c0] & ', ' & $pos[$c1])
        $var += 1
        $c0 += 2
        $c1 += 2

        Sleep(500)
    Next
    Sleep(1000)
    Exit
EndFunc   ;==>_Replay

 

Edited by Lyee

Share this post


Link to post
Share on other sites

I agree with iniwrite.

#include <Misc.au3>
Local $hDLL = DllOpen("user32.dll")
Local $i = 0
Local $pos

FileDelete('rectmp.ini')

_Rec()

Func _Rec()
    While 1
        If _IsPressed("01", $hDLL) Then ;MouseRec
            $pos = MouseGetPos()
            ConsoleWrite('X' & $pos[0] & ', Y' & $pos[1] & @CRLF)
            IniWrite('rectmp.ini', 'GetPos', 'X'&$i, $pos[0])
            IniWrite('rectmp.ini', 'GetPos', 'Y'&$i, $pos[1])
            $i += 1
            While _IsPressed("01", $hDLL) ;Wait for release
                Sleep(50)
            WEnd
        EndIf
        Sleep(100)
        If _IsPressed("50", $hDLL) Then
            _Replay()
        EndIf
    WEnd
EndFunc   ;==>_Rec

Func _Replay()
$ReadSect = IniReadSection('rectmp.ini', 'GetPos')
If IsArray($ReadSect) Then
    For $s = 0 To $ReadSect[0][0]
        $ReadX = IniRead('rectmp.ini', 'GetPos', 'X'&$s, 'empty')
        $ReadY = IniRead('rectmp.ini', 'GetPos', 'Y'&$s, 'empty')
        If $ReadX <> 'empty' And $ReadY <> 'empty' Then
        MouseMove($ReadX, $ReadY)
        ConsoleWrite('REPLAY:' & $ReadX & ', ' & $ReadY& @CRLF)
        Sleep(500)
        Else
        ExitLoop
        EndIf
    Next
EndIf
Sleep(1000)
Exit
EndFunc   ;==>_Replay

 


Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites

Or without iniwrite:

#include <Misc.au3>
Local $hDLL = DllOpen("user32.dll")
Local $i = 0
Local $Coord[50][50]

_Rec()

Func _Rec()
    While 1
        If _IsPressed("01", $hDLL) Then ;MouseRec
            $Coord[$i][0] = MouseGetPos(0)
            $Coord[$i][1] = MouseGetPos(1)
            ConsoleWrite('X' & $Coord[$i][0] & ', Y' & $Coord[$i][1] & @CRLF)
            $i += 1
            While _IsPressed("01", $hDLL) ;Wait for release
                Sleep(50)
            WEnd
        EndIf
        Sleep(100)
        If _IsPressed("50", $hDLL) Then
            _Replay()
        EndIf
    WEnd
EndFunc   ;==>_Rec

Func _Replay()
If IsArray($Coord) Then
    For $s = 0 To Ubound($Coord)
        $ReadX = $Coord[$s][0]
        $ReadY = $Coord[$s][1]
        If $ReadX <> '' And $ReadY <> '' Then
        MouseMove($ReadX, $ReadY)
        ConsoleWrite('REPLAY:' & $ReadX & ', ' & $ReadY& @CRLF)
        Sleep(300)
        Else
            Exit
        EndIf
    Next
EndIf
Sleep(1000)
Exit
EndFunc   ;==>_Replay

 


Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites

I thought this was an interesting idea for a script, so I started a mouse recorder. It records fine, but getting the playback to work is kicking my butt right now. I'm giving up for tonight, but I'll work on it tomorrow (but someone else will probably fix it before I can).

I thought it would be a good idea to also record the delay between clicks to wait for windows to appear. I made it where you can save different click click schemes under different names, having the ability to save multiple schemes under a drop-down menu. Later, we could add the ability to delete schemes that you no longer want to keep.

Check out what I got so far:

 

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Timers.au3>
#include <Misc.au3>
#include <array.au3>

_Singleton("MouseRecord") ; prevents you from accidentially running script twice

$log = "MousePos.ini"

$Form1 = GUICreate("MouseRecord", 526, 235)
$Group1 = GUICtrlCreateGroup("Record", 16, 16, 241, 201)
$Label1 = GUICtrlCreateLabel("Enter a name for a new recording:", 32, 40, 164, 17)
$Input1 = GUICtrlCreateInput("", 32, 64, 209, 21)
$Button1 = GUICtrlCreateButton("Record", 152, 176, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Playback", 272, 16, 233, 201)
$Combo1 = GUICtrlCreateCombo("", 288, 64, 201, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
$Label2 = GUICtrlCreateLabel("Choose a recording to play back:", 288, 40, 160, 17)
$Button2 = GUICtrlCreateButton("Play Back", 416, 176, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
_LoadListView()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            WinSetState("MouseRecord", "", @SW_HIDE)
            $varRecordName = GUICtrlRead($Input1)
            _Record($varRecordName)
            WinSetState("MouseRecord", "", @SW_SHOW)
            _LoadListView()
        Case $Button2
            WinSetState("MouseRecord", "", @SW_HIDE)
            $varReadCombo = GUICtrlRead($Combo1)
            _Playback($varReadCombo)
            WinSetState("MouseRecord", "", @SW_SHOW)
    EndSwitch
WEnd

Func _Record($varRecordName)
    $i = 1
    Do
        $varTimerStart = _Timer_Init()
        If _IsPressed("01") Then
            $varTimerDiff = _Timer_Diff($varTimerStart)
            $varMousePos = MouseGetPos()
            IniWrite($log, $varRecordName, "Position" & $i, $varMousePos[0] & "," & $varMousePos[1])
            IniWrite($log, $varRecordName, "Delay" & $i, $varTimerDiff * 1000)
            $i += 1
            Sleep(400) ; long-ish sleep after click
        EndIf
        Sleep(50) ; short sleep to have quick response to pressing escape key
    Until _IsPressed("1B")
EndFunc

Func _LoadListView()
    GUICtrlSetData($Combo1, "") ; reset data to nothing
    $varComboList = ""
    $arrINISectionNames = IniReadSectionNames($log)
    For $i = 1 To $arrINISectionNames[0]
        $varComboList = $varComboList & $arrINISectionNames[$i] & "|"
    Next
    StringTrimRight($varComboList, 1) ; gets rid of last "|"
    GUICtrlSetData($Combo1, $varComboList)
EndFunc

Func _Playback($varReadCombo)
    MsgBox(0, "", "Playback code goes here")
    #cs
    $arrReadINI = IniReadSection($log, $varReadCombo)
    ;_ArrayDisplay($arrReadINI)
    For $i = 1 To $arrReadINI[0][0]
        $arrReadINIData = StringSplit($arrReadINI[$i/2 + 2][1], ",", 2)
        _ArrayDisplay($arrReadINIData)
        ;MouseMove($arrReadINIData[0], $arrReadINIData[1], 50)
        ;Sleep(IniRead($log, $varReadCombo, "Delay", "5000")
    Next
    #ce
EndFunc

 

 

 

Share this post


Link to post
Share on other sites

Should be good now.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Timers.au3>
#include <Misc.au3>
#include <array.au3>

_Singleton("MouseRecord") ; prevents you from accidentially running script twice

$log = "MousePos.ini"

$Form1 = GUICreate("MouseRecord", 526, 235)
$Group1 = GUICtrlCreateGroup("Record", 16, 16, 241, 201)
$Label1 = GUICtrlCreateLabel("Enter a name for a new recording:", 32, 40, 164, 17)
$Input1 = GUICtrlCreateInput("", 32, 64, 209, 21)
$Button1 = GUICtrlCreateButton("Record", 152, 176, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Playback", 272, 16, 233, 201)
$Combo1 = GUICtrlCreateCombo("", 288, 64, 201, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
$Label2 = GUICtrlCreateLabel("Choose a recording to play back:", 288, 40, 160, 17)
$Button2 = GUICtrlCreateButton("Play Back", 416, 176, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
_LoadListView()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            WinSetState("MouseRecord", "", @SW_HIDE)
            $varRecordName = GUICtrlRead($Input1)
            _Record($varRecordName)
            WinSetState("MouseRecord", "", @SW_SHOW)
            _LoadListView()
        Case $Button2
            WinSetState("MouseRecord", "", @SW_HIDE)
            $varReadCombo = GUICtrlRead($Combo1)
            _Playback($varReadCombo)
            WinSetState("MouseRecord", "", @SW_SHOW)
    EndSwitch
WEnd
;=============================================================================
Func _Record($varRecordName)
    $i = 1
    $varTimerStart = _Timer_Init()
    Do
        $varTimerDiff = _Timer_Diff($varTimerStart)
        If _IsPressed("01") Then
            ConsoleWrite('diff:'&$varTimerDiff &@CRLF)
            $varMousePos = MouseGetPos()
            IniWrite($log, $varRecordName, "Position" & $i, $varMousePos[0] & "," & $varMousePos[1]& "," &$varTimerDiff)
            $i += 1
            Sleep(100) ; long-ish sleep after click
            $varTimerStart = _Timer_Init()
        EndIf
        Sleep(50) ; short sleep to have quick response to pressing escape key
    Until _IsPressed("1B")
EndFunc
;=============================================================================
Func _LoadListView()
    GUICtrlSetData($Combo1, "") ; reset data to nothing
    $varComboList = ""
    $arrINISectionNames = IniReadSectionNames($log)
    If IsArray($arrINISectionNames) Then
    For $i = 1 To $arrINISectionNames[0]
        $varComboList = $varComboList & $arrINISectionNames[$i] & "|"
    Next
    StringTrimRight($varComboList, 1) ; gets rid of last "|"
    GUICtrlSetData($Combo1, $varComboList)
    EndIf
EndFunc
;=============================================================================
Func _Playback($varReadCombo)
    $arrReadINI = IniReadSection($log, $varReadCombo)
    _ArrayDisplay($arrReadINI)
    For $i = 1 To $arrReadINI[0][0]
        $arrReadINIData = StringSplit($arrReadINI[$i][1], ",", 2)
        ConsoleWrite('X - '& $arrReadINIData[0] &' Y - '& $arrReadINIData[1] &' Ms - '&$arrReadINIData[2] &@CRLF)
        MouseMove($arrReadINIData[0], $arrReadINIData[1], 10)
        Sleep($arrReadINIData[2])
    Next
EndFunc

I ended up using the split, and just added the delay there, preventing the need to add another value just for the delay. This way it's all in the same line, and avoids problems when reading since we dont have to skip a value.

Edited by careca

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites

Ur crazy. Thats completely out of my level of coding. Thank you for that

Quote

Should be good now.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Timers.au3>
#include <Misc.au3>
#include <array.au3>

_Singleton("MouseRecord") ; prevents you from accidentially running script twice

$log = "MousePos.ini"

$Form1 = GUICreate("MouseRecord", 526, 235)
$Group1 = GUICtrlCreateGroup("Record", 16, 16, 241, 201)
$Label1 = GUICtrlCreateLabel("Enter a name for a new recording:", 32, 40, 164, 17)
$Input1 = GUICtrlCreateInput("", 32, 64, 209, 21)
$Button1 = GUICtrlCreateButton("Record", 152, 176, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Playback", 272, 16, 233, 201)
$Combo1 = GUICtrlCreateCombo("", 288, 64, 201, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
$Label2 = GUICtrlCreateLabel("Choose a recording to play back:", 288, 40, 160, 17)
$Button2 = GUICtrlCreateButton("Play Back", 416, 176, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
_LoadListView()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            WinSetState("MouseRecord", "", @SW_HIDE)
            $varRecordName = GUICtrlRead($Input1)
            _Record($varRecordName)
            WinSetState("MouseRecord", "", @SW_SHOW)
            _LoadListView()
        Case $Button2
            WinSetState("MouseRecord", "", @SW_HIDE)
            $varReadCombo = GUICtrlRead($Combo1)
            _Playback($varReadCombo)
            WinSetState("MouseRecord", "", @SW_SHOW)
    EndSwitch
WEnd
;=============================================================================
Func _Record($varRecordName)
    $i = 1
    $varTimerStart = _Timer_Init()
    Do
        $varTimerDiff = _Timer_Diff($varTimerStart)
        If _IsPressed("01") Then
            ConsoleWrite('diff:'&$varTimerDiff &@CRLF)
            $varMousePos = MouseGetPos()
            IniWrite($log, $varRecordName, "Position" & $i, $varMousePos[0] & "," & $varMousePos[1]& "," &$varTimerDiff)
            $i += 1
            Sleep(100) ; long-ish sleep after click
            $varTimerStart = _Timer_Init()
        EndIf
        Sleep(50) ; short sleep to have quick response to pressing escape key
    Until _IsPressed("1B")
EndFunc
;=============================================================================
Func _LoadListView()
    GUICtrlSetData($Combo1, "") ; reset data to nothing
    $varComboList = ""
    $arrINISectionNames = IniReadSectionNames($log)
    If IsArray($arrINISectionNames) Then
    For $i = 1 To $arrINISectionNames[0]
        $varComboList = $varComboList & $arrINISectionNames[$i] & "|"
    Next
    StringTrimRight($varComboList, 1) ; gets rid of last "|"
    GUICtrlSetData($Combo1, $varComboList)
    EndIf
EndFunc
;=============================================================================
Func _Playback($varReadCombo)
    $arrReadINI = IniReadSection($log, $varReadCombo)
    _ArrayDisplay($arrReadINI)
    For $i = 1 To $arrReadINI[0][0]
        $arrReadINIData = StringSplit($arrReadINI[$i][1], ",", 2)
        ConsoleWrite('X - '& $arrReadINIData[0] &' Y - '& $arrReadINIData[1] &' Ms - '&$arrReadINIData[2] &@CRLF)
        MouseMove($arrReadINIData[0], $arrReadINIData[1], 10)
        Sleep($arrReadINIData[2])
    Next
EndFunc

I ended up using the split, and just added the delay there, preventing the need to add another value just for the delay. This way it's all in the same line, and avoids problems when reading since we dont have to skip a value.

 

Edited by Lyee

Share this post


Link to post
Share on other sites

@Lyee when you want to post a reply, please do not use the "Quote" button but enter your reply into the input field at the end of the thread and click "Submit".
We know what we have written ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-04-14 - Version 1.5.3.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-04-13 - Version 1.6.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

Hi, i took the script from lyee and modified it a bit to record and replay the (left) mouse clicks.

It does not save the recorded clicks (but can be done with few modification from other posts) ...
You can press ctrl R to start/stop the recordings then Press Ctrl P to Play/stop the recoded clicks. 

The time between clicks is saved too - the code is taken from abberration's post.

 

Recording and replaying can be started/stopped from the tray menue, as well as setup some configuration.

#include <Misc.au3>
#include <Timers.au3>
#include <TrayConstants.au3>

; Original code by Lyee - www.autoitscript.com
;
; Mouse click recorder (atm only left mouse clicks are used)
;Press ctrl/strg r to start recording. Use multiple clicks, the delay between clicks is saved. Press ctrl/strg r again to stop
;After recording, you can use ctrl/strg p to replay the mouse clicks.
;Th
Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode.

If _Singleton("MouseClicker", 1) = 0 Then
    Exit
EndIf

Global Const $MIM_APPLYTOSUBMENUS = 0x80000000, $MIM_BACKGROUND = 0x00000002 ; Constants required for SetMenuColor

Local $hDLL = DllOpen("user32.dll")

HotKeySet('^p', '_ReplaySwitch')                ;Ctrl/Strg p
HotKeySet('^r', '_RecSwitch')                      ;Ctrl/Strg r

AutoItSetOption("TrayAutoPause", 0)

Global $log = -1, $i = 0, $logcounter = 0, $tmptxt = ""
Global $imax = 100, $pos[($imax)][3]            ;0 = x, 1 = y, 2 = delay in ms
Global $clickdelay = 500, $var = 0, $State = 0, $varTimerDiff, $varTimerStart, $repeatcounter = 0
Global $clickrepeat = 0             ;0 = forever, 1 - do it 1 time, 2,3,...n  n*

Global $idREC = TrayCreateItem("Record")
Global $idReplay = TrayCreateItem("Replay")
TrayCreateItem("")
Global $idRepeat = TrayCreateItem("Repeatcount :" & $clickrepeat)
Global $idDelay = TrayCreateItem("Loop Delay :" & $clickdelay & " ms ")
TrayCreateItem("")
Global $idExit = TrayCreateItem("Exit")

SetMenuColor(0,0x00FFFF)

MAIN()

Func MAIN()

    While 1
        Switch $State
            Case 0
            Case 1
                $var = 0
                _Rec()
            Case 2
                _Replay()
            Case 3
                ToolTip("")
                $State = 0
                TrayItemSetState ($idREC,$TRAY_ENABLE)
                TrayItemSetState ($idReplay,$TRAY_ENABLE)
                TrayItemSetText ($idREC,"Record")
                TrayItemSetText ($idReplay,"Replay")
                SetMenuColor(0,0x00FFFF)
        EndSwitch
        Sleeper(15)
    WEnd
EndFunc   ;==>MAIN

Func CheckTray()
    Local $tmp
    Switch TrayGetMsg()
        Case $idExit
            DllClose($hDLL)
            Exit
        Case $idREC
            _RecSwitch()
        Case $idReplay
            _ReplaySwitch()
        Case $idRepeat
            $tmp = Int(InputBox("MouseClicker", "How many times to do a set of clicks ?" & @CRLF & "0 for Endless", "", " M4", 220, 150))
            If @error = 0 Then
                If IsNumber($tmp) Then $clickrepeat = $tmp
                TrayItemSetText($idRepeat, "Repeatcount :" & $tmp)
            EndIf
        Case $idDelay
            $tmp = Int(InputBox("MouseClicker", "Enter a new delay" & @CRLF & "(used at the end of the set)" & @CRLF & "1000 = 1 second" & @CRLF & "min 50, max 999999 ms!" , "", " M6", 220, 180))
            If @error = 0 Then
                If IsNumber($tmp) And $tmp > 49 Then
                    $clickdelay = $tmp
                    TrayItemSetText($idDelay, "Loop Delay :" & $clickdelay & " ms ")
                EndIf
            EndIf
    EndSwitch
EndFunc   ;==>CheckTray

Func _ReplaySwitch()
    If $State = 0 Then
        $State = 2
        $repeatcounter = 0
        $logcounter = 0
        $tmptxt = ""
        TrayItemSetState ($idREC,$TRAY_DISABLE)
        TrayItemSetText ($idReplay,"Stop Replay")
        SetMenuColor(0,0x20FF20)
    ElseIf $State = 2 Then
        $State = 3
        ToolTip("Replay Stopped")
    EndIf
EndFunc   ;==>_ReplaySwitch

Func _RecSwitch()
    If $State = 1 Then
        $State = 3
    ElseIf $State = 0 Then
        $State = 1
        ToolTip("Recording stopped")
    EndIf
EndFunc   ;==>_RecSwitch

Func _Rec()
    TrayItemSetText ($idREC,"Stop Recording")
    TrayItemSetState ($idReplay,$TRAY_DISABLE)
    SetMenuColor(0,0x8181FF)
    Local $mx, $my
    While ($var < ($imax)) And $State = 1
        $mx = MouseGetPos(0)
        $my = MouseGetPos(1)
        ToolTip("Rec " & $var & "/" & ($imax - 1))
        If _IsPressed("01", $hDLL) Then ;MouseRec
            $pos[($var)][0] = $mx
            $pos[($var)][1] = $my
            $pos[($var)][2] = $clickdelay        ;Default delay
            If $var > 0 Then
                $varTimerDiff = _Timer_Diff($varTimerStart)
                $pos[($var - 1)][2] = $varTimerDiff
                $varTimerStart = _Timer_Init()
            ElseIf $var = 0 Then
                $varTimerStart = _Timer_Init()
            EndIf
            $var = $var + 1
            $log = $var - 1

            While _IsPressed("01", $hDLL) ;Wait for release
                Sleeper(50)
            WEnd
            ;ConsoleWrite("-> " & @HOUR & ":" & @MIN & ":" & @SEC & ' MX= ' & $mx & ' MY= ' & $my & " log= " & $log & " tdiff= " & $varTimerDiff & @CRLF)
        EndIf
        Sleeper(50)
    WEnd
    $State = 3
EndFunc   ;==>_Rec

Func _Replay()

    If $log > -1 Then
        For $count = 0 To $log
            If $State = 2 Then
                MouseClick("left", $pos[$count][0], $pos[$count][1])
                ToolTip("Replay " & $count & "/" & $log & $tmptxt)
                ;ConsoleWrite( @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & @CRLF)
                If $count < $log Then
                    Sleeper($pos[$count][2])
                Else
                    Sleeper($clickdelay)
                EndIf
            Else
                $State = 3
            EndIf
        Next

        If $log=0 Then
            $logcounter = $logcounter + 1
            $tmptxt = "  (" & ($logcounter) & ")"
        EndIf

        If $clickrepeat > 0 Then
            $repeatcounter = $repeatcounter + 1
            $tmptxt = "  (" & ($repeatcounter) & ")"
            If $repeatcounter >= $clickrepeat Then $State = 3
        EndIf
        CheckTray()
        Sleeper(500)
    Else
        $State = 3
    EndIf
EndFunc   ;==>_Replay


Func SetMenuColor($iMenuID, $iColor)
    ;code from https://www.autoitscript.com/forum/topic/182563-solved-change-tray-menu-text-color/
    Local $hMenu = TrayItemGetHandle($iMenuID) ; Get the internal menu handle

    Local $hBrush = DllCall("gdi32.dll", "hwnd", "CreateSolidBrush", "int", $iColor)
    $hBrush = $hBrush[0]

    Local $tMenuInfo = DllStructCreate("dword;dword;dword;uint;ptr;dword;ptr")
    DllStructSetData($tMenuInfo, 1, DllStructGetSize($tMenuInfo))
    DllStructSetData($tMenuInfo, 2, BitOR($MIM_APPLYTOSUBMENUS, $MIM_BACKGROUND))
    DllStructSetData($tMenuInfo, 5, $hBrush)

    DllCall("user32.dll", "int", "SetMenuInfo", "hwnd", $hMenu, "struct*", $tMenuInfo)
EndFunc   ;==>SetMenuColor

Func Sleeper($nr)
    Local $varTS = _Timer_Init()
    While _Timer_Diff($varTS) < $nr
        CheckTray()
    WEnd
EndFunc   ;==>Sleeper

 

Edited by Dan_555
bugfix: 1 click recording/replay is allowed now. Tray menu is changing the text and colors for replay, record and waiting state.

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...