Jump to content

Little script can't exit (double while)


Lokomass
 Share

Recommended Posts

Hi,

I've written a little "auto moving mouse" program.

There is 2 buttons : start and quit.

Start button execute auto move. And quit button kill script and exit (like cross click)

But after launch start function, I can't exit the program, can you help me ?

Do i made something wrong ?

 

#include <Timers.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

$Off = 0
$Sleep = 10
$Speed = 10
$Windows = GUICreate("Auto Mouse Mover", 300, 150)
$Start = GUICtrlCreateButton("Start", 50, 50, 75, 50)
$Quit = GUICtrlCreateButton("Quit", 175, 50, 75, 50)    
GUISetState(@SW_SHOW)

$Size = WinGetClientSize("Program Manager")
$Width = $Size[0] / 2
$Height = $Size[1] / 2
    
While 1
    $Message = GUIGetMsg()
    Switch $Message
        Case $Start
            While 1
                MouseMove($Width - 50, $Height - 50, $Speed)
                MouseMove($Width + 50, $Height - 50, $Speed)
                MouseMove($Width + 50, $Height + 50, $Speed)
                MouseMove($Width - 50, $Height + 50, $Speed)
                Sleep($Sleep * 1000)
            Wend
        Case $Quit
            Exit
        Case -3
            Exit
    EndSwitch
WEnd

 

Link to comment
Share on other sites

Link to comment
Share on other sites

Alright, here :

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Local $bStarted = False, $Sleep = 10, $Speed = 10
Local $Windows = GUICreate("Auto Mouse Mover", 300, 150)
Local $Start = GUICtrlCreateButton("Start", 50, 50, 75, 50)
Local $Quit = GUICtrlCreateButton("Quit", 175, 50, 75, 50)
GUISetState(@SW_SHOW)

Local $Size = WinGetClientSize("Program Manager"), $Width = $Size[0] / 2, $Height = $Size[1] / 2
Local $hTime

While True
  Switch GUIGetMsg()
    Case $Start
      $bStarted = True
      $hTime = TimerInit ()
    Case $Quit, $GUI_EVENT_CLOSE
      Exit
  EndSwitch
  If $bStarted And TimerDiff ($hTime) > $Sleep * 1000 Then
    MouseMove($Width - 50, $Height - 50, $Speed)
    MouseMove($Width + 50, $Height - 50, $Speed)
    MouseMove($Width + 50, $Height + 50, $Speed)
    MouseMove($Width - 50, $Height + 50, $Speed)
    $hTime = TimerInit ()
  EndIf
WEnd

 

Edited by Nine
Link to comment
Share on other sites

Hello,

I've update the script, to add a combobox with multiple times (time to quit).

I have an error on my countdown, if I choose for example 2 hours, this don't go under 1 hour, I don't understand what I have made wrong.

Can you help me ?

Thanks for reply

 

#include <_AudioEndpointVolume.au3>
#include <ComboConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ColorConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiComboBox.au3>

#pragma compile(Icon, "Icone.ico")

$Sleep = 10
$Speed = 10

Local $Time
Local $Mute
Local $Volume
Local $Started = False
Local $Style_1 = BitOr($WS_CAPTION, $WS_SYSMENU);
Local $Window = GUICreate("Auto Mouse Mover", 180, 120, -1, -1, $Style_1)
Local $Start = GUICtrlCreateButton("Start", 10, 40, 160, 30)
Local $Quit = GUICtrlCreateButton("Quit", 10, 80, 160, 30)

Local $Style_2 = BitOr($CBS_DROPDOWNLIST, $SS_CENTER, $SS_CENTERIMAGE)
Local $Combo = GUICtrlCreateCombo("", 10, 10, 160, 20, $Style_2)
GUICtrlSetData($Combo, "10 minutes|30 minutes|1 heure|2 heures|3 heures|4 heures")
_GUICtrlComboBox_SetCurSel($Combo, 2)
GUISetState(@SW_SHOW)

$Position = WinGetPos("Auto Mouse Mover")

While 1
    $Message = GUIGetMsg()
    Switch $Message
        Case $Start
            $Volume = Int(_GetMasterVolumeLevelScalar())
            $Mute = _GetMute()
            VolumeUp()
            $Started = True
            $Time = TimerInit()
            GUICtrlSetData($Start, "Running...")
            GUICtrlSetBkColor($Start, 0x90EE90)
            GUICtrlSetState($Start, $GUI_disable)
            $Value = GUICtrlRead($Combo)
            GUICtrlDelete($Combo)
            $Style_3 = BitOr($SS_CENTER, $SS_CENTERIMAGE)
            $Timer = TimerInit()
            $Duree = Temps($Value)
            $Label = GUICtrlCreateLabel(Timer($Timer, $Duree), 10, 10, 160, 20, $Style_3)
        Case $Quit, $GUI_EVENT_CLOSE
            If $Started Then
                VolumeDown($Volume, $Mute)
            EndIf
            Exit
    EndSwitch
    If $Started And TimerDiff($Timer) > 60 * 1000 Then
        $Secondes = Timer($Timer, $Duree)
        If ($Secondes == "0 minute") Then
            VolumeDown($Volume, $Mute)
            Exit
        EndIf
        GUICtrlSetData($Label, $Secondes)
    EndIf
    If $Started And TimerDiff($Time) > $Sleep * 1000 Then
        MouseMove($Position[0], $Position[1], $Speed)
        MouseMove($Position[0] + $Position[2], $Position[1], $Speed)
        MouseMove($Position[0] + $Position[2], $Position[1] + $Position[3], $Speed)
        MouseMove($Position[0], $Position[1] + $Position[3], $Speed)
        $Time = TimerInit()
    EndIf
WEnd

Func Temps($Value)
    $Nombre = StringSplit($Value, ' ')
    $Heure = StringInStr($Value, "heure")
    $Minute = StringInStr($Value, "minute")
    If ($Heure > 0) Then
        $Duree = $Nombre[1] * 3600
    ElseIf ($Minute > 0) Then
        $Duree = $Nombre[1] * 60
    EndIf
    Return $Duree
EndFunc

Func Timer($Timer, $Temps)
    Local $Progression = 0
    Local $Time = 0
    Local $Virgule = 0
    $Timeout = TimerDiff($Timer)
    $Time = $Timeout / 1000
    If ($Time < 10) Then
        $Virgule = StringLeft($Time, 1)
    ElseIf ($Time > 10 And $Time < 100) Then
        $Virgule = StringLeft($Time, 2)
    ElseIf ($Time > 100) Then
        $Virgule = StringLeft($Time, 3)
    EndIf
    $Secondes = $Temps - $Virgule
    Return _FormatElapsedTime($Secondes)
EndFunc

Func _FormatElapsedTime($Input_Seconds)
    If $Input_Seconds < 1 Then Return
    Global $ElapsedMessage = ''
    Global $Input = $Input_Seconds
    Switch $Input_Seconds
        Case 0 To 3599
            GetMinutes()
        Case Else
            GetHours()
            GetMinutes()
    EndSwitch
    Return $ElapsedMessage
EndFunc

Func GetHours()
    $Hours = Int($Input / 3600)
    $Input -= ($Hours * 3600)
    If ($Hours > 1) Then
        $ElapsedMessage &= $Hours & ' heures'
    Else
        $ElapsedMessage &= $Hours & ' heure'
    EndIf
    Return $ElapsedMessage
EndFunc

Func GetMinutes()
    $Minutes = Int($Input / 60)
    $Input -= ($Minutes * 60)
    If ($ElapsedMessage <> "") Then
        $ElapsedMessage &= ', '
    EndIf
    If ($Minutes > 1) Then
        $ElapsedMessage &= $Minutes & ' minutes'
    Else
        $ElapsedMessage &= $Minutes & ' minute'
    EndIf
    Return $ElapsedMessage
EndFunc

Func VolumeUp()
    _SetMute(0)
    _SetMasterVolumeLevelScalar(100)
EndFunc

Func VolumeDown($Volume, $Mute)
    Beep(500, 1000)
    _SetMute($Mute)
    _SetMasterVolumeLevelScalar($Volume)
EndFunc

 

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