Sign in to follow this  
Followers 0
chie

Check if true every 1 sec & if true do action

7 posts in this topic

#1 ·  Posted (edited)

Edit , Check the ölast post for sinal alarm Code

I checkked the Help file & after browsing it I was same stupid as before, after searching forum i came across some alarms that all were not working but I checkked the code & was able to make alarm but it only works if the time is set to lets say 00:00 & if u run the alarm then it works. What i cant understand is How can i make the prog to check for time constantly every 1 second & if the PC time = $time then play sound & keep on checking until next time PC time = $time. Can someone explane it to me please?

HotkeySet("{space}", "MyExit") 
    $hour   = @HOUR
    $minute = @MIN
    $time   = $hour & ":" & $minute
        
        If $time = "01:17" Then         
        MsgBox(0,"", "Test message play sound ")    ;If time =01:17 Display this Message box
        EndIf

    
; Need to keep the program running until you press the hotkey
While 1
    Sleep(100)
WEnd
;;;;;;;;;
Func MyExit() ; Function to exot prog
    Exit 
EndFunc
Edited by chie

Share this post


Link to post
Share on other sites



HotKeySet("{space}", "MyExit")
_CheckTime()
AdlibEnable("_CheckTime", 1000)

; Need to keep the program running until you press the hotkey
While 1
    Sleep(100)
WEnd

Func _CheckTime()
    $hour = @HOUR
    $minute = @MIN
    $time = $hour & ":" & $minute & ":" & @SEC
    ConsoleWrite("Checking Time:" & $time & ":" & @SEC & @LF)

    If $time = "01:17:00" Then
        MsgBox(0, "", "Test message ")   ;If time =01:17 Display this Message box
    EndIf
EndFunc   ;==>_CheckTime
;;;;;;;;;
Func MyExit() ; Function to exot prog
    Exit
EndFunc   ;==>MyExit


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanx But there is 1 thing i was unable to understand & I conmmented the code there:

_CheckTime()                               ; WHY U put this hire? It works also without this, well atleast it worked when i tried.
AdlibEnable("_CheckTime", 1000)
oÝ÷ Ûú®¢×¡¢®q©ázZfz­Öj+zئz+Zj,·
+̶+]¡ë'¢ÔázènW¦ËajÚk¢Ê˧uç%j·ö«¦å{Mú²àjjb¶¸u»­ºi¢­æ¥(Z½éè×-¡×ªÞÛ(Ü(ºWky§fÊ)éºÛ^Ö­i©©²Ö«¶ZÊ)ඬ¢x0zYmç(uè¬r¦z{^u©©mëpyéå¢x%w¬{ayº-¶­«b±Æ®²)ඩ®[飺Ëj{n׫²Ö§uhr÷«ÊØb¥±è¬Âäx"¶W­²æë£ë"qø¥y©©±ëmçZµ¨§¶¢­nmç(º{]£   ð¢¹,j[(jëh×6#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode 
Opt("TrayIconHide", 1) ;hide the icon

$mainwindow = GUICreate("Alarm clock test", 400, 100)
$Go = GUICtrlCreateButton("Go", 5, 10, 50, 20)      ;Play button
$browse = GUICtrlCreateButton("Browse", 5, 32, 50, 20)      ;Browse Button
$e1 = GUICtrlCreateinput(" ", 60 , 10 , 330 , 70)       ;Are Where the chosen song is displayed

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") ; declaring events or something,
GUICtrlSetOnEvent($browse, "Browse")            ; so if u press Browse then $browse function is called
GUICtrlSetOnEvent($Go, "_CheckTime")        ; etc.  
GUISetState(@SW_SHOW)   ; makes Gui Visible


AdlibEnable("_CheckTime", 1000) ; checks time every 1 second

While 1         ;
  Sleep(1000)   ; Just idle around 
WEnd            ;

Func CLOSEClicked()         ;Exit GUI function
    SoundSetWaveVolume(50)  ;if u close GUI
    sleep(100)              ;
  Exit                      ;
EndFunc                     ;

Func Browse()
    ;opens desktop after pressing Browse button & lets u choose files
            $song = FileOpenDialog("Play MP3/WAV sound",@desktopDir,"MP3 sound (*.mp3)|WAV sound (*.wav)",1 + 4)
            SoundSetWaveVolume(0)   ; setting volume
            $mid = $song            
            while 1
            $songstr = stringinstr($mid,"\")
            if $songstr = 0 then ExitLoop
            $mid = stringmid($mid,$songstr+1)
            wend
            $sk = $mid  
            ;Sets chosen song name into the Are Where the chosen song is displayed
            GUICtrlSetData($e1, $sk) 
EndFunc
 
;Alarm settings
Func _CheckTime()
    $hour = @HOUR
    $minute = @MIN
    $time = $hour & ":" & $minute & ":" & @SEC
    ConsoleWrite("Checking Time:" & $time & ":" & @SEC & @LF) ; console will display the countdown
    If $time = "05:09:40" Then  ; if time matches play the sound 
        
        MsgBox(0, "", "Test message ") ;Just a test message to show that countdown works
;~      ----------------------------------------------------------------------------------------
        #cs
        SoundSetWaveVolume(0)
        GUICtrlRead($song)
        SoundPlay($song)
        SoundSetWaveVolume(50)
        #ce
;~      ----------------------------------------------------------------------------------------
EndIf
EndFunc   ;==>_CheckTime
Edited by chie

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
Opt("TrayIconHide", 1) ;hide the icon

$alarm_time = "05:09:40"
$song = ""
$mainwindow = GUICreate("Alarm clock test", 400, 100)
$Go = GUICtrlCreateButton("Go", 5, 10, 50, 20)   ;Play button
$browse = GUICtrlCreateButton("Browse", 5, 32, 50, 20)   ;Browse Button
$e1 = GUICtrlCreateInput(" ", 60, 10, 330, 70)      ;Are Where the chosen song is displayed

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") ; declaring events or something,
GUICtrlSetOnEvent($browse, "Browse")            ; so if u press Browse then $browse function is called
GUICtrlSetOnEvent($Go, "_CheckTime")        ; etc.
GUISetState(@SW_SHOW)   ; makes Gui Visible


AdlibEnable("_CheckTime", 1000) ; checks time every 1 second

While 1   ;
    Sleep(1000)   ; Just idle around
WEnd            ;

Func CLOSEClicked()   ;Exit GUI function
    SoundSetWaveVolume(50)  ;if u close GUI
    Sleep(100)        ;
    Exit            ;
EndFunc   ;==>CLOSEClicked

Func Browse()
    ;opens desktop after pressing Browse button & lets u choose files
    $song = FileOpenDialog("Play MP3/WAV sound", @DesktopDir, "MP3 sound (*.mp3)|WAV sound (*.wav)", 1 + 4)
    SoundSetWaveVolume(0)   ; setting volume
    $mid = $song
    While 1
        $songstr = StringInStr($mid, "\")
        If $songstr = 0 Then ExitLoop
        $mid = StringMid($mid, $songstr + 1)
    WEnd
    $sk = $mid
    ;Sets chosen song name into the Are Where the chosen song is displayed
    GUICtrlSetData($e1, $sk)
EndFunc   ;==>Browse

;Alarm settings
Func _CheckTime()
    $hour = @HOUR
    $minute = @MIN
    $time = $hour & ":" & $minute & ":" & @SEC
;~  ConsoleWrite("Checking Time:" & $time & ":" & @SEC & @LF) ; console will display the countdown
    If $time = $alarm_time Then  ; if time matches play the sound

        MsgBox(0, "", "Test message ") ;Just a test message to show that countdown works
;~   ----------------------------------------------------------------------------------------
;~      #cs
            SoundSetWaveVolume(0)
            GUICtrlRead($song)
            SoundPlay($song)
            SoundSetWaveVolume(50)
;~      #ce
;~   ----------------------------------------------------------------------------------------
    EndIf
EndFunc   ;==>_CheckTime


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

$song = ""
Wow that was really simple. But Why? I understand that u put it there because it must be out of all functions, so all functions can use it? But why the "" marks? Edited by chie

Share this post


Link to post
Share on other sites

Wow that was really simple. But Why? I understand that u put it there because it must be out of all functions, so all functions can use it? But why the "" marks?

Would be the pretty much the same as

Global $song

but being you haven't been declaring vars i did it the way it that way


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Thank you. Well hire is final code for my small alarm, & once i get smarter i will probably make it with input box where the time can be inserted.

#include <GUIConstants.au3>
#include <Date.au3>
Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown
global $song, $Go, $Tray_exititem_item, $Secs, $Mins, $Hour, $time_,$rest_time_window

;~ Gui 1
;~ -------------------------------------------------------------------------------------------------------
$mainwindow = GUICreate("Alarm", 400, 100)
$slider = GUICtrlCreateSlider (190,70,200,20,$TBS_NOTICKS) ;Slider
GUICtrlSetLimit(-1,100,0)   ; change min/max value
GUICtrlSetData(-1,_SoundGetWaveVolume()) ; set cursor
;~ -------------------------------------------------------------------------------------------------------
$browse = GUICtrlCreateButton("Browse", 5, 10, 50, 20)   ;Browse Button
$start = GUICtrlCreateButton("Start", 5, 34, 50, 20)   ;Browse Button
$e1 = GUICtrlCreateInput("", 60, 10, 330, 20)      ;Are Where the chosen song is displayed
;~ -------------------------------------------------------------------------------------------------------
$iniread_Hour = IniRead("C:\myfile.ini", "Alarm", "hour","")
$iniread_Min = IniRead("C:\myfile.ini", "Alarm", "min","")

$input_ALARM_data = GUICtrlCreateCombo ($iniread_Hour, 60,70,40, 20) ; create first item
GUICtrlSetData(-1,"00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24",$iniread_Hour) ; add other item snd set a new default
$input_ALARM_data2 = GUICtrlCreateCombo ($iniread_Min, 100,70,40, 20) ; create first item
GUICtrlSetData(-1,"|00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60",$iniread_Min) ; add other item snd set a new default
;~ -------------------------------------------------------------------------------------------------------
$Checkbox_RestReminder = GUICtrlCreateCheckbox("Remind to rest every 1.H", 60, 38)
GUISetState(@SW_SHOW)   ; makes Gui Visible

;~ Gui 2
;~ -------------------------------------------------------------------------------------------------------
$rest_time_window = GUICreate("RestReminder", 400, 100)
$font="Comic Sans MS"
GUISetFont (30, 400, 1, $font)   ; will display underlined characters
GUICtrlCreateLabel ("TIME TO REST !!!",35,20)
GUICtrlSetColor(-1,0xff) ;blue
GUISetState(@SW_HIDE)   ; makes Gui Visible
;~ *********************************************************************************************************

;~ Tray MENU
;~ ---------------------------------------------------------------------------------------------------------
$Tray_Maximize_item     = TrayCreateItem("Maximize")
$settingsitem   = TrayCreateMenu("Rest opt.")
$Enable   = TrayCreateItem("Enable", $settingsitem)
$Disnable   = TrayCreateItem("Disable", $settingsitem)
TrayCreateItem("")
$Tray_exititem_item       = TrayCreateItem("Exit")
TraySetState(@SW_HIDE)

if GUICtrlRead($Checkbox_RestReminder) = $GUI_UNCHECKED Then TraySetState(4)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func _SoundGetWaveVolume() ; get the et Wav Sound Volume (Author gafrost)
    Local $WaveVol = -1, $p, $ret
    Const $MMSYSERR_NOERROR = 0
    $p = DllStructCreate ("dword")
    If @error Then
        SetError(2)
        Return -2
    EndIf
    $ret = DllCall("winmm.dll", "long", "waveOutGetVolume", "long", -1, "long", DllStructGetPtr ($p))
    If ($ret[0] == $MMSYSERR_NOERROR) Then
        $WaveVol = Round(Dec(StringRight(Hex(DllStructGetData ($p, 1), 8), 4)) / 0xFFFF * 100)
    Else
        SetError(1)
    EndIf
    $Struct=0 
    Return $WaveVol
EndFunc;==>_SoundGetWaveVolume

While 1  
    SoundSetWaveVolume(GUICtrlRead($slider)) ; set slider to current volume value
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
    $msg = GUIGetMsg()
    $msg1 = TrayGetMsg()
    Select
    Case $msg1 = $Tray_exititem_item
        Exit
    Case $msg = $GUI_EVENT_MINIMIZE
        GUISetState(@SW_HIDE,$mainwindow)
        GUISetState(@SW_HIDE,$rest_time_window)
;~ ---------------------------------------------------------------------------------------------------------
    Case $msg = $GUI_EVENT_CLOSE
        _CLOSEClicked() ; call _CLOSEClicked() funtion
;~ ---------------------------------------------------------------------------------------------------------
    Case $msg1 = $Tray_Maximize_item
        GUISetState(@SW_SHOW,$mainwindow)
        GUISetState(@SW_RESTORE,$mainwindow)
;~ --------------------------------------------------------------
;~ Changing Tray icon modes , Blinking & not blinking
case $msg1 = $Enable
        TraySetState(8)
        GUICtrlSetState($Checkbox_RestReminder,$GUI_CHECKED)
    case $msg1 = $Disnable
        TraySetState(4)
        GUICtrlSetState($Checkbox_RestReminder,$GUI_UNCHECKED)
;~ --------------------------------------------------------------
    Case $msg = $Checkbox_RestReminder And BitAND(GUICtrlRead($Checkbox_RestReminder), $GUI_CHECKED) = $GUI_CHECKED
        TraySetState(8)
    Case $msg = $Checkbox_RestReminder And BitAND(GUICtrlRead($Checkbox_RestReminder), $GUI_UNCHECKED) = $GUI_UNCHECKED
        TraySetState(4)
;~ --------------------------------------------------------------
    Case $msg = $browse
        _Browse() ; call _Browse() funtion
    Case $msg = $start
        GUISetState(@SW_HIDE,$mainwindow)
        AdlibEnable("_CheckTime", 60000) ; checks time every 1 minute (calls _CheckTime() function )
    EndSelect
WEnd

Func _CLOSEClicked()   ;Exit GUI function
        $Hwnd = WinGetHandle('')
        If $Hwnd = $rest_time_window Then
            GUISetState(@SW_HIDE,$rest_time_window)
        ElseIf $Hwnd = $mainwindow Then
            Exit
        EndIf
;~     SoundSetWaveVolume(50)  ;if u close GUI
    Sleep(100)        
EndFunc 

Func _Browse()
    ;opens desktop after pressing Browse button & lets u choose files
    $song = FileOpenDialog("Play MP3/WAV sound", @DesktopDir, "MP3 sound (*.mp3;*.wav;*.wma)", 1 + 4)

    ;~ SoundSetWaveVolume(0)   ; setting volume
    $mid = $song
    While 1
        $songstr = StringInStr($mid, "\")
        If $songstr = 0 Then ExitLoop
        $mid = StringMid($mid, $songstr + 1)
    WEnd
    $sk = $mid
    ;Sets chosen song name into the Are Where the chosen song is displayed
    GUICtrlSetData($e1, $sk)
;~  AdlibEnable("_CheckTime", 60000) ; checks time every 1 minute
EndFunc   ;==>Browse

;Alarm settings
Func _CheckTime()
    IniWrite("C:\myfile.ini", "Alarm", "hour",GUICtrlRead($input_ALARM_data))
    IniWrite("C:\myfile.ini", "Alarm", "min",GUICtrlRead($input_ALARM_data2))
    
    $hour = @HOUR
    $minute = @MIN
    $time_ = $hour & ":" & $minute
    
if GUICtrlRead($Checkbox_RestReminder) = $GUI_CHECKED Then ; Reast reminder time matching
If $time_ = "00:00" Then _play_it()
If $time_ = "01:00" Then _play_it()
If $time_ = "02:00" Then _play_it()
If $time_ = "03:00" Then _play_it()
If $time_ = "04:00" Then _play_it()
If $time_ = "05:00" Then _play_it()
If $time_ = "06:00" Then _play_it()
If $time_ = "07:00" Then _play_it()
If $time_ = "08:00" Then _play_it()
If $time_ = "09:00" Then _play_it()
If $time_ = "10:00" Then _play_it()
If $time_ = "11:00" Then _play_it()
If $time_ = "12:00" Then _play_it()
If $time_ = "13:00" Then _play_it()
If $time_ = "14:00" Then _play_it()
If $time_ = "15:00" Then _play_it()
If $time_ = "16:00" Then _play_it()
If $time_ = "17:00" Then _play_it()
If $time_ = "18:00" Then _play_it()
If $time_ = "19:00" Then _play_it()
If $time_ = "20:00" Then _play_it()
If $time_ = "21:00" Then _play_it()
If $time_ = "22:00" Then _play_it()
If $time_ = "23:00" Then _play_it()
EndIf

If $time_ = GUICtrlRead($input_ALARM_data) & ":" & GUICtrlRead($input_ALARM_data2) Then  ; if time matches play the sound
;~   -------------------------------------
        GUICtrlSetData($slider,100) ; set slider to 100 & Volume = 100 then
        GUICtrlRead($song); read the song
        SoundPlay($song) ; play it
;~   -------------------------------------
    EndIf
EndFunc 

Func _play_it()
;~   ----------------------------------------------------------------------------------------
        GUISetState(@SW_SHOW,$rest_time_window)
        GUISetState(@SW_RESTORE,$rest_time_window)
        GUICtrlSetData($slider,100) ; set slider to 100 & Volume = 100 then
        GUICtrlRead($song); read the song
        SoundPlay($song) ; play it
;~   ----------------------------------------------------------------------------------------
EndFunc
Edited by chie

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0