Jump to content

Timing Function


Recommended Posts

Hi everyone,

I have this script:

; Script Start - Add your code below here

#include <GUIConstantsEx.au3> ; Required for GUI.

HotKeySet ( "{ESC}", "Terminate" ) ; Set a hotkey to terminate the script.

Global $Counter1 ; Variable used as part of the counter below.
Global $Counter2 ; Variable used as part of the counter below.
Global $Left_bottom_y ; Important co-ordinate of the TrueCrypt 'Volume Format' window.
Global $Left_top_x ; Important co-ordinate of the TrueCrypt 'Volume Format' window.
Global $Left_top_y ; Important co-ordinate of the TrueCrypt 'Volume Format' window.
Global $Right_top_x ; Important co-ordinate of the TrueCrypt 'Volume Format' window.

; Create GUI.
GUICreate ( "TrueCrypt Random Mouse Mover", 300, 150 ) ; Create a dialog box that when displayed is centered.
GUISetState ( @SW_SHOW ) ; Will display an empty dialog box.

; Create input fields
$InputHours = GUICtrlCreateInput ( "", 10, 20, 20, 20 ) ; Create an input field for the user to input the amount of time they want the script to run for. Field is for hours.
$InputMinutes = GUICtrlCreateInput ( "", 75, 20, 20, 20 ) ; Create an input field for the user to input the amount of time they want the script to run for. Field is for minutes.
$InputSeconds = GUICtrlCreateInput ( "", 150, 20, 20, 20 ) ; Create an input field for the user to input the amount of time they want the script to run for. Field is for seconds.
GUICtrlCreateLabel ( "Hours", 35, 24 ) ; Label for the Hours input control.
GUICtrlCreateLabel ( "Minutes", 100, 24 ) ; Label for the Minutes input control.
GUICtrlCreateLabel ( "Seconds", 175, 24 ) ; Label for the Seconds input control.
GUICtrlSetTip ( $InputHours, "Enter the time you wish the script to run for, in hours (default is 00)" ) ; Tooltip for the hours input control.
GUICtrlSetTip ( $InputMinutes, "Enter the time you wish the script to run for, in minutes (default is 03)" ) ; Tooltip for the minutes input control.
GUICtrlSetTip ( $InputSeconds, "Enter the time you wish the script to run for, in seconds (default is 00)" ) ; Tooltip for the seconds input control.
GUICtrlSetData ( $InputHours, "00" ) ; Sets default for the hours input control.
GUICtrlSetData ( $InputMinutes, "03" ) ; Sets default for the minutes input control.
GUICtrlSetData ( $InputSeconds, "00" ) ; Sets default for the seconds input control.

; Create buttons.
$ButtonRun = GUICtrlCreateButton ( "Run", 10, 60, 40, 25 ) ; Create a button to run the random mouse movement part of the script.
$ButtonExit = GUICtrlCreateButton ( "Exit", 10, 100, 40, 25 ) ; Create a button to exit the script.

; Create radio buttons.
$RadioFast = GUICtrlCreateRadio ( "Fast", 80, 100 ) ; Create a radio button for fast mouse movement.
GUICtrlSetTip ( $RadioFast, "Select if you wish the mouse movement to be fast." ) ; Tooltip for the fast radio button control.
$RadioNormal = GUICtrlCreateRadio ( "Normal", 80, 80 ) ; Create a radio button for normal mouse movement.
GUICtrlSetTip ( $RadioNormal, "Select if you wish the mouse movement to be a combination of fast and slow." ) ; Tooltip for the normal radio button control.
$RadioSlow = GUICtrlCreateRadio ( "Slow", 80, 60 ) ; Create a radio button for slow mouse movement.
GUICtrlSetTip ( $RadioSlow, "Select if you wish the mouse movement to be slow." ) ; Tooltip for the slow radio button control.
GUICtrlSetState ($RadioNormal, $GUI_CHECKED ) ; Set the normal radio button to be checked.

While 1 ; Run the GUI until the dialog is closed.
    $msg = GUIGetMsg()

    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop

        Case $msg = $ButtonRun And ( $RadioNormal And BitAND ( GUICtrlRead ( $RadioNormal ), $GUI_CHECKED ) = $GUI_CHECKED ) ; Run button is clicked and Normal radio button is selected.
            TrueCrypt_Test()
            Time_Calculate()
            $Input1 = Time_Calculate()
            Normal_Random_Mouse_Movements ( $Input1 ) ; If TrueCrypt is running and is up to the 'Volume Format' window, then continue on with the script. Parameter passed to function to avoid the 'GUICtrlRead returns Control ID when not in the same function as the GUICtrlCreateInput statement' bug described in the Notes above.
            ; MsgBox ( 0, "Debugging Only", "Normal speed was selected." )
            Normal_Repeat_Script()

        Case $msg = $ButtonRun And ( $RadioFast And BitAND ( GUICtrlRead ( $RadioFast ), $GUI_CHECKED ) = $GUI_CHECKED ) ; Run button is clicked and Fast radio button is selected.
            TrueCrypt_Test()
            Time_Calculate()
            $Input1 = Time_Calculate()
            Fast_Random_Mouse_Movements( $Input1 ) ; If TrueCrypt is running and is up to the 'Volume Format' window, then continue on with the script. Parameter passed to function to avoid the 'GUICtrlRead returns Control ID when not in the same function as the GUICtrlCreateInput statement' bug described in the Notes above.
            ; MsgBox ( 0, "Debugging Only", "Fast speed was selected." )
            Fast_Repeat_Script()

        Case $msg = $ButtonRun And ( $RadioSlow And BitAND ( GUICtrlRead ( $RadioSlow ), $GUI_CHECKED ) = $GUI_CHECKED ) ; Run button is clicked and Slow radio button is selected.
            TrueCrypt_Test()
            Time_Calculate()
            $Input1 = Time_Calculate()
            Slow_Random_Mouse_Movements( $Input1 ) ; If TrueCrypt is running and is up to the 'Volume Format' window, then continue on with the script. Parameter passed to function to avoid the 'GUICtrlRead returns Control ID when not in the same function as the GUICtrlCreateInput statement' bug described in the Notes above.
            ; MsgBox ( 0, "Debugging Only", "Slow speed was selected." )
            Slow_Repeat_Script()

        Case $msg = $ButtonExit
            Terminate()
    EndSelect

WEnd

Func Fast_Random_Mouse_Movements( Const $Input1) ; Randomly move the mouse within the TrueCrypt Volume Creation Wizard window (weighted to faster mouse movements). Parameter passed to function  to avoid the 'GUICtrlRead returns Control ID when not in the same function as the GUICtrlCreateInput statement' bug described in the Notes above.
    TrueCrypt_Window_Locate( $Left_top_x, $Right_top_x, $Left_top_y, $Left_bottom_y ) ; Locate TrueCrypt 'Volume Format' window.

    $Counter1 = 0 ; Initialises a counter.
    $Counter2 = $Input1 * 0.75 ; Conversion. User inputs time in seconds they want script to run, but counter below counts runs of the Random_Mouse_Movements function, which is totally different (so user inputs '10', script will run 10 times, not for 10 seconds). One 'fast' run is roughly one and a half seconds, depending on how long each mouse movement is.

    While $Counter1 < $Counter2
        $Mouse_Speed = Random ( 1, 20, 1 ) ; Select a random integer between 1 and 20 (1 to 100 is the allowable value range, with a higher number equalling slower movement) for the mouse movement speed for the MouseMove function.
        Move_Mouse ( $Mouse_Speed ) ; Move the mouse cursor.
    WEnd

EndFunc

Func Fast_Repeat_Script() ; Fast speed mouse movement repeat function.
    $UserAnswer1 = MsgBox ( 4356, "Repeat?", "Do you wish to repeat the script, which will run for another "&$Input1&" seconds?" ) ; Ask user if they want to run the script again.

    If $UserAnswer1 = 6 Then ; If user clicks 'Yes'
        Fast_Random_Mouse_Movements( $Input1 ) ; Run script again.
        Fast_Repeat_Script() ; Ask the question again, otherwise script will only offer the user the chance to run again the one single time.
    ElseIf $UserAnswer1 = 7 Then ; If user clicks 'No'
        WinActivate ( "TrueCrypt Volume Creation Wizard", "Volume Format" ) ; Make the TrueCrypt window the active one.
        Send ( "!f" ) ; Sends Alt+F to TrueCrypt window to simulate click on Format button.
        Terminate() ; Exit script.
    Else ; If the return code is something other than Yes or No.
        MsgBox ( 0, "Error", "Unknown error." )
    EndIf

EndFunc

Func Move_Mouse( $Mouse_Speed ) ; Mouse movement.
    $Mousex = Random ( $Left_top_x, $Right_top_x, 1 ) ; Select a random integer between the minimum and maximum x co-ordinates of the TrueCrypt Volume Creation Wizard window.
    $Mousey = Random ( $Left_top_y, $Left_bottom_y, 1 ) ; Select a random integer between the minimum and maximum y co-ordinates of the TrueCrypt Volume Creation Wizard window.
    WinActivate ( "TrueCrypt Volume Creation Wizard", "Volume Format" ) ; Make the TrueCrypt window the active one.
    MouseMove ( $Mousex, $Mousey, $Mouse_Speed ) ; Move the mouse, using the random x co-ordinate, the random y co-ordinate and the random mouse speed.
    $Counter1 = $Counter1 + 1 ; Increment the counter.
    Sleep ( 500 ) ; Sleep for 500ms to avoid 100% CPU usage.
    ; MsgBox ( 0, "For Debugging Only", "Counter1 = "&$Counter1&", Counter2 = "&$Counter2 )
EndFunc

Func Normal_Random_Mouse_Movements( Const $Input1) ; Randomly move the mouse within the TrueCrypt Volume Creation Wizard window (uses the full range of MouseMove values, the default function used if either the 'fast' or 'slow' checkboxes are not ticked). Parameter passed to function  to avoid the 'GUICtrlRead returns Control ID when not in the same function as the GUICtrlCreateInput statement' bug described in the Notes above.
    TrueCrypt_Window_Locate( $Left_top_x, $Right_top_x, $Left_top_y, $Left_bottom_y ) ; Locate TrueCrypt 'Volume Format' window.

    $Counter1 = 0 ; Initialises a counter.
    $Counter2 = $Input1 * 0.5 ; Conversion. User inputs time in seconds they want script to run, but counter below counts runs of the Random_Mouse_Movements function, which is totally different (so user inputs '10', script will run 10 times, not for 10 seconds). One 'normal' run is roughly two seconds, depending on how long each mouse movement is.

    While $Counter1 < $Counter2
        $Mouse_Speed = Random ( 1, 100, 1 ) ; Select a random integer between 1 and 100 (the allowable value range) for the mouse movement speed for the MouseMove function.
        Move_Mouse ( $Mouse_Speed ) ; Move the mouse cursor.
    WEnd

EndFunc

Func Normal_Repeat_Script() ; Normal speed mouse movement repeat function.
    $UserAnswer1 = MsgBox ( 4356, "Repeat?", "Do you wish to repeat the script, which will run for another "&$Input1&" seconds?" ) ; Ask user if they want to run the script again.

    If $UserAnswer1 = 6 Then ; If user clicks 'Yes'
        Normal_Random_Mouse_Movements( $Input1 ) ; Run script again.
        ; MsgBox ( 0, "Debugging Only", "Input1 = "&$Input1 )
        Normal_Repeat_Script() ; Ask the question again, otherwise script will only offer the user the chance to run again the one single time.
    ElseIf $UserAnswer1 = 7 Then ; If user clicks 'No'
        WinActivate ( "TrueCrypt Volume Creation Wizard", "Volume Format" ) ; Make the TrueCrypt window the active one.
        Send ( "!f" ) ; Sends Alt+F to TrueCrypt window to simulate click on Format button.
        Terminate() ; Exit script.
    Else ; If the return code is something other than Yes or No.
        MsgBox ( 0, "Error", "Unknown error." )
    EndIf

EndFunc

Func Slow_Random_Mouse_Movements( Const $Input1) ; Randomly move the mouse within the TrueCrypt Volume Creation Wizard window (weighted to slower mouse movements). Parameter passed to function  to avoid the 'GUICtrlRead returns Control ID when not in the same function as the GUICtrlCreateInput statement' bug described in the Notes above.
    TrueCrypt_Window_Locate( $Left_top_x, $Right_top_x, $Left_top_y, $Left_bottom_y ) ; Locate TrueCrypt 'Volume Format' window.

    $Counter1 = 0 ; Initialises a counter.
    $Counter2 = $Input1 * 0.33 ; Conversion. User inputs time in seconds they want script to run, but counter below counts runs of the Random_Mouse_Movements function, which is totally different (so user inputs '10', script will run 10 times, not for 10 seconds). One 'slow' run is roughly three seconds, depending on how long each mouse movement is.

    While $Counter1 < $Counter2
        $Mouse_Speed = Random ( 80, 100, 1 ) ; Select a random integer between 80 and 100 (1 to 100 is the allowable value range, with a higher number equalling slower movement) for the MouseMove function.
        Move_Mouse ( $Mouse_Speed ) ; Move the mouse cursor.
    WEnd

EndFunc

Func Slow_Repeat_Script() ; Slow speed mouse movement repeat function.
    $UserAnswer1 = MsgBox ( 4356, "Repeat?", "Do you wish to repeat the script, which will run for another "&$Input1&" seconds?" ) ; Ask user if they want to run the script again.

    If $UserAnswer1 = 6 Then ; If user clicks 'Yes'
        Slow_Random_Mouse_Movements( $Input1 ) ; Run script again.
        Slow_Repeat_Script() ; Ask the question again, otherwise script will only offer the user the chance to run again the one single time.
    ElseIf $UserAnswer1 = 7 Then ; If user clicks 'No'
        WinActivate ( "TrueCrypt Volume Creation Wizard", "Volume Format" ) ; Make the TrueCrypt window the active one.
        Send ( "!f" ) ; Sends Alt+F to TrueCrypt window to simulate click on Format button.
        Terminate() ; Exit script.
    Else ; If the return code is something other than Yes or No.
        MsgBox ( 0, "Error", "Unknown error." )
    EndIf

EndFunc

Func Terminate() ; Close the script when the hotkey (ESC) is pressed.
    Exit 0 ; Exits the script.
EndFunc

Func Time_Calculate(); Time calculator, to convert hours:minutes:seconds (as entered by the user) to seconds.
    Const $Time_Calc1 = GUICtrlRead ( $InputHours ) * 60 * 60 ; Convert the hours entered by the user to seconds.
    Const $Time_Calc2 = GUICtrlRead ( $InputMinutes ) * 60 ; Convert the minutes entered by the user to seconds.
    Const $Time_Calc3 = GUICtrlRead ( $InputSeconds ) ; Read the seconds entered by the user.
    Const $Time_Calc4 = $Time_Calc1 + $Time_Calc2 + $Time_Calc3 ; Add the converted hours, minutes and seconds together to get a value in seconds.
    $Input1 = $Time_Calc4 ; Read the value in the input box and assign to variable. This is to avoid the 'GUICtrlRead returns Control ID when not in the same function as the GUICtrlCreateInput statement' bug described in the Notes above.
    ; MsgBox ( 0, "Debugging Only", "Input1 = "&$Input1 )
    Return ( $Input1 ) ; Return $Input1 value to calling function.
EndFunc

Func TrueCrypt_Test() ; Test if TrueCrypt is running and the 'Volume Format' window is displaying.
    $Test1 = ProcessExists ( "TrueCrypt.exe" ) ; Is the TrueCrypt process running?
    $Test2 = WinExists ( "TrueCrypt Volume Creation Wizard", "Volume Format" ) ; Is TrueCrypt up to the 'Volume Format' window as yet?

    If $Test1 = 0 Then ; If the TrueCrypt process is not running (note, I deliberately did not use the single line - instead of the two that this line and the one above requires - If ProcessExists ( "TrueCrypt.exe" ) Then as without a GoTo command, I could not work out how to make it continue if the answer was "Yes it exists").
        MsgBox ( 4112, "Error", "TrueCrypt is not running. Please ensure TrueCrypt is running before running this script again." ) ; Display error message.
        Terminate() ; Exit script.
    ElseIf $Test2 = 0 Then
        MsgBox ( 4112, "Error", "TrueCrypt is not yet up to the 'Volume Format' window. Please ensure TrueCrypt is up to the 'Volume Format' window before running this script again." ) ; Display error message.
        Terminate() ; Exit script.
    EndIf

EndFunc

Func TrueCrypt_Window_Locate( $Temp1, $Temp2, $Temp3, $Temp4 ) ; Locate TrueCrypt 'Volume Format' window.
    ; Get location of TrueCrypt Volume Creation Wizard window so the mouse movements can be constrained to co-ordinates within this window (TrueCrypt only counts mouse movement within the Volume Creation Wizard window towards the random pool).
    $Size = WinGetPos ( "TrueCrypt Volume Creation Wizard", "Volume Format" ) ; Get the position of the TrueCrypt Volume Creation Wizard window and store in this variable (which is an array).
    $Left_top_x = $Size[0] ; x co-ordinate of top left of TrueCrypt Volume Creation Wizard window.
    $Left_top_y = $Size[1] ; y co-ordinate of top left of TrueCrypt Volume Creation Wizard window.
    $Right_top_x = $Size[0] + $Size[2] ; x co-ordinate of top right of TrueCrypt Volume Creation Wizard window.
    $Right_top_y = $Size[1] ; y co-ordinate of top right of TrueCrypt Volume Creation Wizard window.
    $Left_bottom_x = $Size[0] ; x co-ordinate of bottom left of TrueCrypt Volume Creation Wizard window.
    $Left_bottom_y = $Size[1] + $Size[3] ; y co-ordinate of bottom left of TrueCrypt Volume Creation Wizard window.
    $Right_bottom_x = $Size[0] + $Size[2] ; x co-ordinate of bottom right of TrueCrypt Volume Creation Wizard window.
    $Right_bottom_y = $Size[1] + $Size[3] ; y co-ordinate of bottom right of TrueCrypt Volume Creation Wizard window.
    Return $Left_top_x
    Return $Right_top_x
    Return $Left_top_y
    Return $Left_bottom_y
EndFunc

Basically, the script moves the mouse randomly at the TrueCrypt volume format window (so as to increase the randomness of the key generation pool). The script works ok, except for one little bit. When you run the script, I have the user enter the time they want the mouse to move for in hh:mm:ss. Now, I've been trying to come up with a timing function that actually works, based on the time. So, if the user enters 2 minutes, the script will run for exactly 2 minutes. At the moment, it takes an estimate of how long each mouse movement takes, and then uses that to estimate the number of mouse movements it needs to do to make up the user entered time. Very messy. Anyway, I've been playing around with converting the current time from hh:mm:ss to ss, then convert the user entered time from hh:mm:ss to ss, then add the two values together, then convert this ss value to hh:mm:ss. I haven't gotten very far with that though, and I can't help but thinking there must be an easier way to say "Script, if the user tells you to run for 10 seconds, then run for 10 seconds then exit'. Can anyone suggest anything?

Thanks,

CM

Link to comment
Share on other sites

Hi everyone,

I have this script:

; Script Start - Add your code below here

#include <GUIConstantsEx.au3> ; Required for GUI.

HotKeySet ( "{ESC}", "Terminate" ) ; Set a hotkey to terminate the script.

Global $Counter1 ; Variable used as part of the counter below.
Global $Counter2 ; Variable used as part of the counter below.
Global $Left_bottom_y ; Important co-ordinate of the TrueCrypt 'Volume Format' window.
Global $Left_top_x ; Important co-ordinate of the TrueCrypt 'Volume Format' window.
Global $Left_top_y ; Important co-ordinate of the TrueCrypt 'Volume Format' window.
Global $Right_top_x ; Important co-ordinate of the TrueCrypt 'Volume Format' window.

; Create GUI.
GUICreate ( "TrueCrypt Random Mouse Mover", 300, 150 ) ; Create a dialog box that when displayed is centered.
GUISetState ( @SW_SHOW ) ; Will display an empty dialog box.

; Create input fields
$InputHours = GUICtrlCreateInput ( "", 10, 20, 20, 20 ) ; Create an input field for the user to input the amount of time they want the script to run for. Field is for hours.
$InputMinutes = GUICtrlCreateInput ( "", 75, 20, 20, 20 ) ; Create an input field for the user to input the amount of time they want the script to run for. Field is for minutes.
$InputSeconds = GUICtrlCreateInput ( "", 150, 20, 20, 20 ) ; Create an input field for the user to input the amount of time they want the script to run for. Field is for seconds.
GUICtrlCreateLabel ( "Hours", 35, 24 ) ; Label for the Hours input control.
GUICtrlCreateLabel ( "Minutes", 100, 24 ) ; Label for the Minutes input control.
GUICtrlCreateLabel ( "Seconds", 175, 24 ) ; Label for the Seconds input control.
GUICtrlSetTip ( $InputHours, "Enter the time you wish the script to run for, in hours (default is 00)" ) ; Tooltip for the hours input control.
GUICtrlSetTip ( $InputMinutes, "Enter the time you wish the script to run for, in minutes (default is 03)" ) ; Tooltip for the minutes input control.
GUICtrlSetTip ( $InputSeconds, "Enter the time you wish the script to run for, in seconds (default is 00)" ) ; Tooltip for the seconds input control.
GUICtrlSetData ( $InputHours, "00" ) ; Sets default for the hours input control.
GUICtrlSetData ( $InputMinutes, "03" ) ; Sets default for the minutes input control.
GUICtrlSetData ( $InputSeconds, "00" ) ; Sets default for the seconds input control.

; Create buttons.
$ButtonRun = GUICtrlCreateButton ( "Run", 10, 60, 40, 25 ) ; Create a button to run the random mouse movement part of the script.
$ButtonExit = GUICtrlCreateButton ( "Exit", 10, 100, 40, 25 ) ; Create a button to exit the script.

; Create radio buttons.
$RadioFast = GUICtrlCreateRadio ( "Fast", 80, 100 ) ; Create a radio button for fast mouse movement.
GUICtrlSetTip ( $RadioFast, "Select if you wish the mouse movement to be fast." ) ; Tooltip for the fast radio button control.
$RadioNormal = GUICtrlCreateRadio ( "Normal", 80, 80 ) ; Create a radio button for normal mouse movement.
GUICtrlSetTip ( $RadioNormal, "Select if you wish the mouse movement to be a combination of fast and slow." ) ; Tooltip for the normal radio button control.
$RadioSlow = GUICtrlCreateRadio ( "Slow", 80, 60 ) ; Create a radio button for slow mouse movement.
GUICtrlSetTip ( $RadioSlow, "Select if you wish the mouse movement to be slow." ) ; Tooltip for the slow radio button control.
GUICtrlSetState ($RadioNormal, $GUI_CHECKED ) ; Set the normal radio button to be checked.

While 1 ; Run the GUI until the dialog is closed.
    $msg = GUIGetMsg()

    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop

        Case $msg = $ButtonRun And ( $RadioNormal And BitAND ( GUICtrlRead ( $RadioNormal ), $GUI_CHECKED ) = $GUI_CHECKED ) ; Run button is clicked and Normal radio button is selected.
            TrueCrypt_Test()
            Time_Calculate()
            $Input1 = Time_Calculate()
            Normal_Random_Mouse_Movements ( $Input1 ) ; If TrueCrypt is running and is up to the 'Volume Format' window, then continue on with the script. Parameter passed to function to avoid the 'GUICtrlRead returns Control ID when not in the same function as the GUICtrlCreateInput statement' bug described in the Notes above.
            ; MsgBox ( 0, "Debugging Only", "Normal speed was selected." )
            Normal_Repeat_Script()

        Case $msg = $ButtonRun And ( $RadioFast And BitAND ( GUICtrlRead ( $RadioFast ), $GUI_CHECKED ) = $GUI_CHECKED ) ; Run button is clicked and Fast radio button is selected.
            TrueCrypt_Test()
            Time_Calculate()
            $Input1 = Time_Calculate()
            Fast_Random_Mouse_Movements( $Input1 ) ; If TrueCrypt is running and is up to the 'Volume Format' window, then continue on with the script. Parameter passed to function to avoid the 'GUICtrlRead returns Control ID when not in the same function as the GUICtrlCreateInput statement' bug described in the Notes above.
            ; MsgBox ( 0, "Debugging Only", "Fast speed was selected." )
            Fast_Repeat_Script()

        Case $msg = $ButtonRun And ( $RadioSlow And BitAND ( GUICtrlRead ( $RadioSlow ), $GUI_CHECKED ) = $GUI_CHECKED ) ; Run button is clicked and Slow radio button is selected.
            TrueCrypt_Test()
            Time_Calculate()
            $Input1 = Time_Calculate()
            Slow_Random_Mouse_Movements( $Input1 ) ; If TrueCrypt is running and is up to the 'Volume Format' window, then continue on with the script. Parameter passed to function to avoid the 'GUICtrlRead returns Control ID when not in the same function as the GUICtrlCreateInput statement' bug described in the Notes above.
            ; MsgBox ( 0, "Debugging Only", "Slow speed was selected." )
            Slow_Repeat_Script()

        Case $msg = $ButtonExit
            Terminate()
    EndSelect

WEnd

Func Fast_Random_Mouse_Movements( Const $Input1) ; Randomly move the mouse within the TrueCrypt Volume Creation Wizard window (weighted to faster mouse movements). Parameter passed to function  to avoid the 'GUICtrlRead returns Control ID when not in the same function as the GUICtrlCreateInput statement' bug described in the Notes above.
    TrueCrypt_Window_Locate( $Left_top_x, $Right_top_x, $Left_top_y, $Left_bottom_y ) ; Locate TrueCrypt 'Volume Format' window.

    $Counter1 = 0 ; Initialises a counter.
    $Counter2 = $Input1 * 0.75 ; Conversion. User inputs time in seconds they want script to run, but counter below counts runs of the Random_Mouse_Movements function, which is totally different (so user inputs '10', script will run 10 times, not for 10 seconds). One 'fast' run is roughly one and a half seconds, depending on how long each mouse movement is.

    While $Counter1 < $Counter2
        $Mouse_Speed = Random ( 1, 20, 1 ) ; Select a random integer between 1 and 20 (1 to 100 is the allowable value range, with a higher number equalling slower movement) for the mouse movement speed for the MouseMove function.
        Move_Mouse ( $Mouse_Speed ) ; Move the mouse cursor.
    WEnd

EndFunc

Func Fast_Repeat_Script() ; Fast speed mouse movement repeat function.
    $UserAnswer1 = MsgBox ( 4356, "Repeat?", "Do you wish to repeat the script, which will run for another "&$Input1&" seconds?" ) ; Ask user if they want to run the script again.

    If $UserAnswer1 = 6 Then ; If user clicks 'Yes'
        Fast_Random_Mouse_Movements( $Input1 ) ; Run script again.
        Fast_Repeat_Script() ; Ask the question again, otherwise script will only offer the user the chance to run again the one single time.
    ElseIf $UserAnswer1 = 7 Then ; If user clicks 'No'
        WinActivate ( "TrueCrypt Volume Creation Wizard", "Volume Format" ) ; Make the TrueCrypt window the active one.
        Send ( "!f" ) ; Sends Alt+F to TrueCrypt window to simulate click on Format button.
        Terminate() ; Exit script.
    Else ; If the return code is something other than Yes or No.
        MsgBox ( 0, "Error", "Unknown error." )
    EndIf

EndFunc

Func Move_Mouse( $Mouse_Speed ) ; Mouse movement.
    $Mousex = Random ( $Left_top_x, $Right_top_x, 1 ) ; Select a random integer between the minimum and maximum x co-ordinates of the TrueCrypt Volume Creation Wizard window.
    $Mousey = Random ( $Left_top_y, $Left_bottom_y, 1 ) ; Select a random integer between the minimum and maximum y co-ordinates of the TrueCrypt Volume Creation Wizard window.
    WinActivate ( "TrueCrypt Volume Creation Wizard", "Volume Format" ) ; Make the TrueCrypt window the active one.
    MouseMove ( $Mousex, $Mousey, $Mouse_Speed ) ; Move the mouse, using the random x co-ordinate, the random y co-ordinate and the random mouse speed.
    $Counter1 = $Counter1 + 1 ; Increment the counter.
    Sleep ( 500 ) ; Sleep for 500ms to avoid 100% CPU usage.
    ; MsgBox ( 0, "For Debugging Only", "Counter1 = "&$Counter1&", Counter2 = "&$Counter2 )
EndFunc

Func Normal_Random_Mouse_Movements( Const $Input1) ; Randomly move the mouse within the TrueCrypt Volume Creation Wizard window (uses the full range of MouseMove values, the default function used if either the 'fast' or 'slow' checkboxes are not ticked). Parameter passed to function  to avoid the 'GUICtrlRead returns Control ID when not in the same function as the GUICtrlCreateInput statement' bug described in the Notes above.
    TrueCrypt_Window_Locate( $Left_top_x, $Right_top_x, $Left_top_y, $Left_bottom_y ) ; Locate TrueCrypt 'Volume Format' window.

    $Counter1 = 0 ; Initialises a counter.
    $Counter2 = $Input1 * 0.5 ; Conversion. User inputs time in seconds they want script to run, but counter below counts runs of the Random_Mouse_Movements function, which is totally different (so user inputs '10', script will run 10 times, not for 10 seconds). One 'normal' run is roughly two seconds, depending on how long each mouse movement is.

    While $Counter1 < $Counter2
        $Mouse_Speed = Random ( 1, 100, 1 ) ; Select a random integer between 1 and 100 (the allowable value range) for the mouse movement speed for the MouseMove function.
        Move_Mouse ( $Mouse_Speed ) ; Move the mouse cursor.
    WEnd

EndFunc

Func Normal_Repeat_Script() ; Normal speed mouse movement repeat function.
    $UserAnswer1 = MsgBox ( 4356, "Repeat?", "Do you wish to repeat the script, which will run for another "&$Input1&" seconds?" ) ; Ask user if they want to run the script again.

    If $UserAnswer1 = 6 Then ; If user clicks 'Yes'
        Normal_Random_Mouse_Movements( $Input1 ) ; Run script again.
        ; MsgBox ( 0, "Debugging Only", "Input1 = "&$Input1 )
        Normal_Repeat_Script() ; Ask the question again, otherwise script will only offer the user the chance to run again the one single time.
    ElseIf $UserAnswer1 = 7 Then ; If user clicks 'No'
        WinActivate ( "TrueCrypt Volume Creation Wizard", "Volume Format" ) ; Make the TrueCrypt window the active one.
        Send ( "!f" ) ; Sends Alt+F to TrueCrypt window to simulate click on Format button.
        Terminate() ; Exit script.
    Else ; If the return code is something other than Yes or No.
        MsgBox ( 0, "Error", "Unknown error." )
    EndIf

EndFunc

Func Slow_Random_Mouse_Movements( Const $Input1) ; Randomly move the mouse within the TrueCrypt Volume Creation Wizard window (weighted to slower mouse movements). Parameter passed to function  to avoid the 'GUICtrlRead returns Control ID when not in the same function as the GUICtrlCreateInput statement' bug described in the Notes above.
    TrueCrypt_Window_Locate( $Left_top_x, $Right_top_x, $Left_top_y, $Left_bottom_y ) ; Locate TrueCrypt 'Volume Format' window.

    $Counter1 = 0 ; Initialises a counter.
    $Counter2 = $Input1 * 0.33 ; Conversion. User inputs time in seconds they want script to run, but counter below counts runs of the Random_Mouse_Movements function, which is totally different (so user inputs '10', script will run 10 times, not for 10 seconds). One 'slow' run is roughly three seconds, depending on how long each mouse movement is.

    While $Counter1 < $Counter2
        $Mouse_Speed = Random ( 80, 100, 1 ) ; Select a random integer between 80 and 100 (1 to 100 is the allowable value range, with a higher number equalling slower movement) for the MouseMove function.
        Move_Mouse ( $Mouse_Speed ) ; Move the mouse cursor.
    WEnd

EndFunc

Func Slow_Repeat_Script() ; Slow speed mouse movement repeat function.
    $UserAnswer1 = MsgBox ( 4356, "Repeat?", "Do you wish to repeat the script, which will run for another "&$Input1&" seconds?" ) ; Ask user if they want to run the script again.

    If $UserAnswer1 = 6 Then ; If user clicks 'Yes'
        Slow_Random_Mouse_Movements( $Input1 ) ; Run script again.
        Slow_Repeat_Script() ; Ask the question again, otherwise script will only offer the user the chance to run again the one single time.
    ElseIf $UserAnswer1 = 7 Then ; If user clicks 'No'
        WinActivate ( "TrueCrypt Volume Creation Wizard", "Volume Format" ) ; Make the TrueCrypt window the active one.
        Send ( "!f" ) ; Sends Alt+F to TrueCrypt window to simulate click on Format button.
        Terminate() ; Exit script.
    Else ; If the return code is something other than Yes or No.
        MsgBox ( 0, "Error", "Unknown error." )
    EndIf

EndFunc

Func Terminate() ; Close the script when the hotkey (ESC) is pressed.
    Exit 0 ; Exits the script.
EndFunc

Func Time_Calculate(); Time calculator, to convert hours:minutes:seconds (as entered by the user) to seconds.
    Const $Time_Calc1 = GUICtrlRead ( $InputHours ) * 60 * 60 ; Convert the hours entered by the user to seconds.
    Const $Time_Calc2 = GUICtrlRead ( $InputMinutes ) * 60 ; Convert the minutes entered by the user to seconds.
    Const $Time_Calc3 = GUICtrlRead ( $InputSeconds ) ; Read the seconds entered by the user.
    Const $Time_Calc4 = $Time_Calc1 + $Time_Calc2 + $Time_Calc3 ; Add the converted hours, minutes and seconds together to get a value in seconds.
    $Input1 = $Time_Calc4 ; Read the value in the input box and assign to variable. This is to avoid the 'GUICtrlRead returns Control ID when not in the same function as the GUICtrlCreateInput statement' bug described in the Notes above.
    ; MsgBox ( 0, "Debugging Only", "Input1 = "&$Input1 )
    Return ( $Input1 ) ; Return $Input1 value to calling function.
EndFunc

Func TrueCrypt_Test() ; Test if TrueCrypt is running and the 'Volume Format' window is displaying.
    $Test1 = ProcessExists ( "TrueCrypt.exe" ) ; Is the TrueCrypt process running?
    $Test2 = WinExists ( "TrueCrypt Volume Creation Wizard", "Volume Format" ) ; Is TrueCrypt up to the 'Volume Format' window as yet?

    If $Test1 = 0 Then ; If the TrueCrypt process is not running (note, I deliberately did not use the single line - instead of the two that this line and the one above requires - If ProcessExists ( "TrueCrypt.exe" ) Then as without a GoTo command, I could not work out how to make it continue if the answer was "Yes it exists").
        MsgBox ( 4112, "Error", "TrueCrypt is not running. Please ensure TrueCrypt is running before running this script again." ) ; Display error message.
        Terminate() ; Exit script.
    ElseIf $Test2 = 0 Then
        MsgBox ( 4112, "Error", "TrueCrypt is not yet up to the 'Volume Format' window. Please ensure TrueCrypt is up to the 'Volume Format' window before running this script again." ) ; Display error message.
        Terminate() ; Exit script.
    EndIf

EndFunc

Func TrueCrypt_Window_Locate( $Temp1, $Temp2, $Temp3, $Temp4 ) ; Locate TrueCrypt 'Volume Format' window.
    ; Get location of TrueCrypt Volume Creation Wizard window so the mouse movements can be constrained to co-ordinates within this window (TrueCrypt only counts mouse movement within the Volume Creation Wizard window towards the random pool).
    $Size = WinGetPos ( "TrueCrypt Volume Creation Wizard", "Volume Format" ) ; Get the position of the TrueCrypt Volume Creation Wizard window and store in this variable (which is an array).
    $Left_top_x = $Size[0] ; x co-ordinate of top left of TrueCrypt Volume Creation Wizard window.
    $Left_top_y = $Size[1] ; y co-ordinate of top left of TrueCrypt Volume Creation Wizard window.
    $Right_top_x = $Size[0] + $Size[2] ; x co-ordinate of top right of TrueCrypt Volume Creation Wizard window.
    $Right_top_y = $Size[1] ; y co-ordinate of top right of TrueCrypt Volume Creation Wizard window.
    $Left_bottom_x = $Size[0] ; x co-ordinate of bottom left of TrueCrypt Volume Creation Wizard window.
    $Left_bottom_y = $Size[1] + $Size[3] ; y co-ordinate of bottom left of TrueCrypt Volume Creation Wizard window.
    $Right_bottom_x = $Size[0] + $Size[2] ; x co-ordinate of bottom right of TrueCrypt Volume Creation Wizard window.
    $Right_bottom_y = $Size[1] + $Size[3] ; y co-ordinate of bottom right of TrueCrypt Volume Creation Wizard window.
    Return $Left_top_x
    Return $Right_top_x
    Return $Left_top_y
    Return $Left_bottom_y
EndFunc

Basically, the script moves the mouse randomly at the TrueCrypt volume format window (so as to increase the randomness of the key generation pool). The script works ok, except for one little bit. When you run the script, I have the user enter the time they want the mouse to move for in hh:mm:ss. Now, I've been trying to come up with a timing function that actually works, based on the time. So, if the user enters 2 minutes, the script will run for exactly 2 minutes. At the moment, it takes an estimate of how long each mouse movement takes, and then uses that to estimate the number of mouse movements it needs to do to make up the user entered time. Very messy. Anyway, I've been playing around with converting the current time from hh:mm:ss to ss, then convert the user entered time from hh:mm:ss to ss, then add the two values together, then convert this ss value to hh:mm:ss. I haven't gotten very far with that though, and I can't help but thinking there must be an easier way to say "Script, if the user tells you to run for 10 seconds, then run for 10 seconds then exit'. Can anyone suggest anything?

Thanks,

CM

Hi,

eg. for your while loop in function Normal_Random_Mouse_Movements:

;you need to 
#include <date.au3>
;at the beginning of your script

Func Normal_Random_Mouse_Movements( Const $Input1) ; Randomly move the mouse within the TrueCrypt Volume Creation Wizard window (uses the full range of MouseMove values, the default function used if either the 'fast' or 'slow' checkboxes are not ticked). Parameter passed to function  to avoid the 'GUICtrlRead returns Control ID when not in the same function as the GUICtrlCreateInput statement' bug described in the Notes above.
    TrueCrypt_Window_Locate( $Left_top_x, $Right_top_x, $Left_top_y, $Left_bottom_y ) ; Locate TrueCrypt 'Volume Format' window.
    $starttime = @YEAR & "/" & @MON & "/" & @WDAY & " " & @HOUR & ":" & @MIN ":" & @SEC  ; get starttime
 
    While 1
        $Mouse_Speed = Random ( 1, 100, 1 ) ; Select a random integer between 1 and 100 (the allowable value range) for the mouse movement speed for the MouseMove function.
        Move_Mouse ( $Mouse_Speed ) ; Move the mouse cursor.
        If _DateDiff ("s", $starttime, _NowCalc ()) >= $input1 Then ExitLoop ; exit loop if difference in seconds is greater then the users
    WEnd

EndFunc

;-))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

Hi,

eg. for your while loop in function Normal_Random_Mouse_Movements:

;you need to 
#include <date.au3>
;at the beginning of your script

Func Normal_Random_Mouse_Movements( Const $Input1) ; Randomly move the mouse within the TrueCrypt Volume Creation Wizard window (uses the full range of MouseMove values, the default function used if either the 'fast' or 'slow' checkboxes are not ticked). Parameter passed to function  to avoid the 'GUICtrlRead returns Control ID when not in the same function as the GUICtrlCreateInput statement' bug described in the Notes above.
    TrueCrypt_Window_Locate( $Left_top_x, $Right_top_x, $Left_top_y, $Left_bottom_y ) ; Locate TrueCrypt 'Volume Format' window.
    $starttime = @YEAR & "/" & @MON & "/" & @WDAY & " " & @HOUR & ":" & @MIN ":" & @SEC  ; get starttime
 
    While 1
        $Mouse_Speed = Random ( 1, 100, 1 ) ; Select a random integer between 1 and 100 (the allowable value range) for the mouse movement speed for the MouseMove function.
        Move_Mouse ( $Mouse_Speed ) ; Move the mouse cursor.
        If _DateDiff ("s", $starttime, _NowCalc ()) >= $input1 Then ExitLoop ; exit loop if difference in seconds is greater then the users
    WEnd

EndFunc

;-))

Stefan

Hi,

Thanks for that. I've copied the lines into my script, and when I run it, I get this error:

Line 172 (File "C:\Downloads\TrueCryptVolumeFormat.au3"):

$starttime = @YEAR & "/" & @MON & "/" & @WDAY & " " & @HOUR & ":" & @MIN ":" & @SEC

$starttime = ^ ERROR

Error: Error in expression.

It seems to be pointing to the @ symbol in front of the Year variable, but the @ symbol is what you're meant to use for those, isn't it?

Link to comment
Share on other sites

Hi,

Thanks for that. I've copied the lines into my script, and when I run it, I get this error:

Line 172 (File "C:\Downloads\TrueCryptVolumeFormat.au3"):

$starttime = @YEAR & "/" & @MON & "/" & @WDAY & " " & @HOUR & ":" & @MIN ":" & @SEC

$starttime = ^ ERROR

Error: Error in expression.

It seems to be pointing to the @ symbol in front of the Year variable, but the @ symbol is what you're meant to use for those, isn't it?

You left out an ampersand after @Min

$starttime = @YEAR & "/" & @MON & "/" & @WDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

You left out an ampersand after @Min

$starttime = @YEAR & "/" & @MON & "/" & @WDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC

Heh - 99ojo left it out, and I didn't pick it up either :) Ok, now that I've put the missing ampersand in, the script runs - but according to my watch, a 10 second run only lasts 3 seconds. This is a little bizarre. :)
Link to comment
Share on other sites

That's all right, I didn't pick it up either. I've double checked what I copied into the script, and it does match the above. Despite that, a 20 second run finishes instantly. There must be something in the rest of the code that isn't quite right. I thought it may have been the value of $Input1, but from re-reading my code, that variable is simply converted from hh:mm:ss into seconds, and then passed to the other functions. If I enter 00:00:20, that should give a value of 20. And if I am understanding the new If _DateDiff line correctly, it gets the current time, then runs, then checks the current time again, and if it is less less than $Input1, then run again. I can't see anything wrong with that either.

Edited by romulous
Link to comment
Share on other sites

Hi,

for debugging just put a

MsgBox (0,"", _DateDiff ("s", $starttime, _NowCalc ()) & @CRLF & $input1)

before the if statement to check the values.

;-))

Stefan

Ok, what that produced was a dialog with two values (I was using 20 seconds for the time):

259205

20

Immediately after this, I received the prompt from Normal_Repeat_Script():

$UserAnswer1 = MsgBox ( 4356, "Repeat?", "Do you wish to repeat the script, which will run for another "&$Input1&" seconds?" ) ; Ask user if they want to run the script again.

20 would be $Input1, which is correct. That 259205 doesn't look right though. That would mean - if I understand it - that as 259205 is > 20, then the loop is exited, and thus why the script only runs one single mouse movement? So, the next question I have to answer then, would be where is it getting 259205 from?

Link to comment
Share on other sites

Sry,

just change @WDAY to @MDAY for variable $starttime.

@WDAY gives you numbers from 1 to 7 corresponding to Sunday to Saturday.

@MDAY gives you the current day of the month.

;-))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

Sry,

just change @WDAY to @MDAY for variable $starttime.

@WDAY gives you numbers from 1 to 7 corresponding to Sunday to Saturday.

@MDAY gives you the current day of the month.

;-))

Stefan

Yes, I think that was it. I just ran the script using a value of 3 minutes. The run - hand timed by stopwatch, so there is a little margin of error there - ran 3min 1sec (and 36 one hundredths).

Awesome, it looks like my script now has a proper - i.e. based on the actual time instead of a wild guess - timing function :) Thanks guys. I'm going to experiment now with putting a little window on screen that shows a countdown to when the run is due to be finished to make it a little more user friendly.

Link to comment
Share on other sites

I was going to suggest using TimerInit() and Timerdiff() rather than drag the date in there

With $input specified in ms:

Func Fast_Random_Mouse_Movements( Const $Input1) ; Randomly move the mouse within the TrueCrypt Volume Creation Wizard window (weighted to faster mouse movements). Parameter passed to function  to avoid the 'GUICtrlRead returns Control ID when not in the same function as the GUICtrlCreateInput statement' bug described in the Notes above.
    TrueCrypt_Window_Locate( $Left_top_x, $Right_top_x, $Left_top_y, $Left_bottom_y ) ; Locate TrueCrypt 'Volume Format' window.

    $Counter1 = Timerinit() ; Initialises a counter.
    While Timerdiff($counter1) < $input
        $Mouse_Speed = Random ( 1, 20, 1 ) ; Select a random integer between 1 and 20 (1 to 100 is the allowable value range, with a higher number equalling slower movement) for the mouse movement speed for the MouseMove function.
        Move_Mouse ( $Mouse_Speed ) ; Move the mouse cursor.
    WEnd

EndFunc

Disabling this line in mouse_move:

$Counter1 = $Counter1 + 1

Also, to increase the randomness of the random function, you should seed it using SRandom.

Throw this in the top of your script:

Srandom(Timerinit())

Edited by TurionAltec
Link to comment
Share on other sites

Hi,

eg. for your while loop in function Normal_Random_Mouse_Movements:

;-))

Stefan

While I think Datediff is overkill, I made the following change to your code:

;you need to 
#include <date.au3>
;at the beginning of your script

Func Normal_Random_Mouse_Movements( Const $Input1) ; Randomly move the mouse within the TrueCrypt Volume Creation Wizard window (uses the full range of MouseMove values, the default function used if either the 'fast' or 'slow' checkboxes are not ticked). Parameter passed to function  to avoid the 'GUICtrlRead returns Control ID when not in the same function as the GUICtrlCreateInput statement' bug described in the Notes above.
    TrueCrypt_Window_Locate( $Left_top_x, $Right_top_x, $Left_top_y, $Left_bottom_y ) ; Locate TrueCrypt 'Volume Format' window.
    $starttime = @YEAR & "/" & @MON & "/" & @WDAY & " " & @HOUR & ":" & @MIN ":" & @SEC  ; get starttime
 
    Do
        $Mouse_Speed = Random ( 1, 100, 1 ) ; Select a random integer between 1 and 100 (the allowable value range) for the mouse movement speed for the MouseMove function.
        Move_Mouse ( $Mouse_Speed ) ; Move the mouse cursor.
    Until   _DateDiff ("s", $starttime, _NowCalc ()) >= $input1

EndFunc

Rather than have an infinite While loop with a If-Then-Exitloop in it, why not just use the native logic checking in a Do-Until or While-Wend loop?

Link to comment
Share on other sites

While I think Datediff is overkill, I made the following change to your code:

;you need to 
#include <date.au3>
;at the beginning of your script

Func Normal_Random_Mouse_Movements( Const $Input1) ; Randomly move the mouse within the TrueCrypt Volume Creation Wizard window (uses the full range of MouseMove values, the default function used if either the 'fast' or 'slow' checkboxes are not ticked). Parameter passed to function  to avoid the 'GUICtrlRead returns Control ID when not in the same function as the GUICtrlCreateInput statement' bug described in the Notes above.
    TrueCrypt_Window_Locate( $Left_top_x, $Right_top_x, $Left_top_y, $Left_bottom_y ) ; Locate TrueCrypt 'Volume Format' window.
    $starttime = @YEAR & "/" & @MON & "/" & @WDAY & " " & @HOUR & ":" & @MIN ":" & @SEC  ; get starttime
 
    Do
        $Mouse_Speed = Random ( 1, 100, 1 ) ; Select a random integer between 1 and 100 (the allowable value range) for the mouse movement speed for the MouseMove function.
        Move_Mouse ( $Mouse_Speed ) ; Move the mouse cursor.
    Until   _DateDiff ("s", $starttime, _NowCalc ()) >= $input1

EndFunc

Rather than have an infinite While loop with a If-Then-Exitloop in it, why not just use the native logic checking in a Do-Until or While-Wend loop?

:),

this is the second time you've got me with much more simple code.

Hope i'm learning well and improve my forest style coding. :P

Although i was thinking, there must be a diff for time, if there is one for date (TimerDiff, :) ).

Lazy bumps don't rtfm and just start coding till it runs and then try to improve code in another way. :idea:

;-)))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

I was going to suggest using TimerInit() and Timerdiff() rather than drag the date in there

With $input specified in ms:

Func Fast_Random_Mouse_Movements( Const $Input1) ; Randomly move the mouse within the TrueCrypt Volume Creation Wizard window (weighted to faster mouse movements). Parameter passed to function  to avoid the 'GUICtrlRead returns Control ID when not in the same function as the GUICtrlCreateInput statement' bug described in the Notes above.
    TrueCrypt_Window_Locate( $Left_top_x, $Right_top_x, $Left_top_y, $Left_bottom_y ) ; Locate TrueCrypt 'Volume Format' window.

    $Counter1 = Timerinit() ; Initialises a counter.
    While Timerdiff($counter1) < $input
        $Mouse_Speed = Random ( 1, 20, 1 ) ; Select a random integer between 1 and 20 (1 to 100 is the allowable value range, with a higher number equalling slower movement) for the mouse movement speed for the MouseMove function.
        Move_Mouse ( $Mouse_Speed ) ; Move the mouse cursor.
    WEnd

EndFunc

Disabling this line in mouse_move:

$Counter1 = $Counter1 + 1

Also, to increase the randomness of the random function, you should seed it using SRandom.

Throw this in the top of your script:

Srandom(Timerinit())

Thanks. I tried your changes to 99ojo's script, and it worked fine. I then made a copy of the file and tried to use what you have above, but with mixed results. The script runs - but it only runs once before it displays the 'do you want to run again' prompt. I think there may have also been a slight typing error there too - you have $input. That should have been $input1 shouldn't it? Anyway, I now just have to work out why it only runs once before ending. Edited by romulous
Link to comment
Share on other sites

Ok, the only potential cause of this problem that I can see is that TimerDiff counts in ms, while the rest of the script counts in seconds. So, what I think I need to do is to add something to Time_Calculate() to convert the seconds to ms. I don't know what though, I guess I'll have to hit google and see if I can find out how many ms in a second first, and then go from there.

Link to comment
Share on other sites

$millSecs = $Seconds*1000

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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