Jump to content

Push Up Timer


 Share

Recommended Posts

Greetings and Salutations,

This is my first post on the Autoit Forum, I am attempting to create a script that essentially starts up first thing in the morning the moment the computer is unlocked. Then continues to run in the back ground giving alerts every hour on the hour till the computer is locked in the evening to go home. At no point outside the hours of say 8-9:30am and before 4-6:30pm should the timer shut off. Past those time is should self terminate. The script is a reminder to do 10 push ups on the hour every hour at work.

This is what I have thus far. Will continue to post updates if anyone is interested. Please feel free to comment or critique.

P.S. This start was provided by someone else, everything I will build on top of this from here on...

Thank you.

-------------------------------------------------------------------

#include <GUIConstants.au3>

#include <Date.au3>

Global Const $SM_VIRTUALWIDTH = 78

Global Const $SM_VIRTUALHEIGHT = 79

$VIRTUALDESKTOPWIDTH = DLLCall("user32.dll","int","GetSystemMetrics","int",$SM_VIRTUALWIDTH)

$VIRTUALDESKTOPWIDTH = $VIRTUALDESKTOPWIDTH[0]

$VIRTUALDESKTOPHEIGHT = DLLCall("user32.dll","int","GetSystemMetrics","int",$SM_VIRTUALHEIGHT)

$VIRTUALDESKTOPHEIGHT = $VIRTUALDESKTOPHEIGHT[0]

$gui = GUICreate("Push Up Timer",$VIRTUALDESKTOPWIDTH,$VIRTUALDESKTOPHEIGHT,0,0)

opt("TrayIconDebug",1)

GUICtrlCreateLabel("Push Up Timer", 10,10)

GUISetState()

$timer = TimerInit()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

Exit

EndSelect

Wend

Link to comment
Share on other sites

I am looking for ideas, help with code and pretty much everything and anything people want to offer. As mentioned I am relatively new to Autoit and so any help would be most welcome.

When I say the computer is locked, I am referring to the state of computer, if you hit Windows Key 'L' for example, or Ctrl + Atl +Del and click on Lock Computer. Which is usually the state of the computer when you leave home from work. Won't be logging off, and won't be powering down.

Link to comment
Share on other sites

Updated Code

Global Const $SM_VIRTUALWIDTH = 78

Global Const $SM_VIRTUALHEIGHT = 79

$VIRTUALDESKTOPWIDTH = DLLCall("user32.dll","int","GetSystemMetrics","int",$SM_VIRTUALWIDTH)

$VIRTUALDESKTOPWIDTH = $VIRTUALDESKTOPWIDTH[0]

$VIRTUALDESKTOPHEIGHT = DLLCall("user32.dll","int","GetSystemMetrics","int",$SM_VIRTUALHEIGHT)

$VIRTUALDESKTOPHEIGHT = $VIRTUALDESKTOPHEIGHT[0]

$begin = TimerInit()

While 1

if TimerDiff($begin) > 3000 THEN

time()

$begin = TimerInit()

EndIf

sleep(500)

WEnd

func time()

For $i = 5 to 1 Step -1

$destination = @Systemdir & "\oobe\images\images.jpg"

SplashImageOn("Splash Screen", $destination,$VIRTUALDESKTOPWIDTH,$VIRTUALDESKTOPHEIGHT,1)

Sleep(300); wait for the image to display 3 seconds.

SplashOff()

Sleep(300)

Next

EndFunc

Link to comment
Share on other sites

If someone is feeling up to it and wants to figure out how to convert it, found .Net of detecting if the system is locked or not

http://www.codeproject.com/Purgatory/Detec...slockunlock.asp

SciTE for AutoItDirections for Submitting Standard UDFs

 

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

 

Link to comment
Share on other sites

This might be easier to work with: http://techsupt.winbatch.com/TS/T000001048F24.html

OpenInputDesktop

(DF_ALLOWOTHERACCOUNTHOOK, TRUE,DESKTOP_CREATEMENU |

DESKTOP_CREATEWINDOW |DESKTOP_ENUMERATE |

DESKTOP_HOOKCONTROL |DESKTOP_WRITEOBJECTS |

DESKTOP_READOBJECTS |DESKTOP_SWITCHDESKTOP |GENERIC_WRITE);

and if OpenInputDesktop return NULL, the session is locked.

another way?

This can be converted easy enough I would think.

On Error Resume Next
HKEY_CURRENT_USER = &H80000001

strComputer = "crowtrobot2"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = "Control Panel\Desktop"
ValueName = "ScrnSave.exe"
objWMIService.GetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue
strValue = Replace(strValue, "\", "\\")

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_Process Where ExecutablePath ='" & strValue & "'")

If colItems.Count > 0 Then
    Wscript.Echo "The computer is locked."
Else
    Wscript.Echo "The computer is not locked."
End If
Edited by GaryFrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

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

 

Link to comment
Share on other sites

Direct conversion:

$strValue = ""
$HKEY_CURRENT_USER = 0x80000001

$strComputer = @ComputerName

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\default:StdRegProv")

$strKeyPath = "Control Panel\Desktop"
$ValueName = "ScrnSave.exe"
$objWMIService.GetStringValue($HKEY_CURRENT_USER, $strKeyPath, $ValueName, $strValue)
$strValue = StringReplace($strValue, "\", "\\")

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")

$colItems = $objWMIService.ExecQuery("Select * From Win32_Process Where ExecutablePath ='" & $strValue & "'")

If $colItems.Count > 0 Then
    MsgBox(0,"Locked?", "The computer is locked.")
Else
    MsgBox(0,"Locked?", "The computer is not locked.")
EndIf

Think this only works if the screen saver has kicked in.....

Edited by GaryFrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

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

 

Link to comment
Share on other sites

This seems to work:

Global Const $DESKTOP_ENUMERATE = 0x40
Global Const $SPI_GETSCREENSAVERRUNNING = 114
Global Const $DESKTOP_SWITCHDESKTOP = 0x100

HotKeySet("{ESC}", "_Terminate")
AdlibEnable("IsDeskTopLocked", 500)

While 1
    Sleep(10)
WEnd

Func IsDeskTopLocked()
    Local $p_lngHwnd, $p_lngRtn, $p_lngErr, $p_lngScreenSaver, $p_blnIsScreenSaver
    
;~    ' ------------------------------------------
;~    ' First check for screen saver one of 2 ways,
;~    '     based of OS
;~    ' ------------------------------------------
    If @OSTYPE = "WIN32_WINDOWS"  Then
;~       ' ---------------------------------------
;~       ' Pre W2K -- Note, will only be TRUE if
;~       '     the "Password Protected" box is
;~       '     checked.
;~       ' ---------------------------------------
        $p_lngHwnd = DllCall("user32.dll", "int", "OpenDesktopA", "str", "screen-saver", "int", 0, "int", False, "int", $DESKTOP_ENUMERATE)
        If $p_lngHwnd[0] <> 0 Then
            $p_blnIsScreenSaver = True
        Else
            $p_blnIsScreenSaver = False
        EndIf
    Else
;~       ' ---------------------------------------
;~       ' W2K+ -- Will determine if screen saver
;~       '     is running whether or not the
;~       '     "Password Protected" box is checked
;~       ' ---------------------------------------
        $p_lngRtn = DllCall("user32.dll", "int", "SystemParametersInfoA", "int", $SPI_GETSCREENSAVERRUNNING, "int", 0, "int", $p_lngScreenSaver, "int", 0)
        If $p_lngRtn[0] = 0 Then
            ConsoleWrite("Error detecting screen saver" & @LF)
        Else
            $p_blnIsScreenSaver = $p_lngScreenSaver
        EndIf

    EndIf

;~    ' ------------------------------------------
;~    ' If screen saver is *not* running, then
;~    '     check for locked workstation
;~    ' ------------------------------------------
    If $p_blnIsScreenSaver Then
        If @OSTYPE = "WIN32_WINDOWS"  Then
            ConsoleWrite("Screen saver is running..., Handle #" & $p_lngHwnd[0] & @LF)
            $p_lngHwnd = DllCall("user32.dll", "int", "CloseDesktop", "int", $p_lngHwnd[0])
        Else
            ConsoleWrite("Screen saver is running on W2K+" & @LF)
        EndIf

    Else
        $p_lngHwnd = DllCall("user32.dll", "int", "OpenDesktopA", "str", "Default", "int", 0, "int", False, "int", $DESKTOP_SWITCHDESKTOP)

        If $p_lngHwnd[0] = 0 Then
            ConsoleWrite("Error with OpenDesktop" & @LF)

        Else
            $p_lngRtn = DllCall("user32.dll", "int", "SwitchDesktop", "int", $p_lngHwnd[0])
            $p_lngErr = _GetLastErrorMessage()

            If $p_lngRtn[0] = 0 Then
                If $p_lngErr = 0 Then
                    ConsoleWrite("Desktop is locked" & @LF)
                Else
                    ConsoleWrite("Error with SwitchDesktop" & @LF)
                EndIf
            Else
                ConsoleWrite("Not locked!" & @LF)
            EndIf

            $p_lngHwnd = DllCall("user32.dll", "int", "CloseDesktop", "int", $p_lngHwnd[0])

        EndIf
    EndIf
EndFunc   ;==>IsDeskTopLocked

Func _Terminate()
    Exit
EndFunc   ;==>_Terminate

;===============================================
;    _GetLastErrorMessage($DisplayMsgBox="")
;    Format the last windows error as a string and return it
;    if $DisplayMsgBox <> "" Then it will display a message box w/ the error
;    Return        Window's error as a string
;===============================================
Func _GetLastErrorMessage($DisplayMsgBox = "")
    Local $ret, $s
    Local $p = DllStructCreate("char[4096]")
    Local Const $FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000

    If @error Then Return ""

    $ret = DllCall("Kernel32.dll", "int", "GetLastError")

    $ret = DllCall("kernel32.dll", "int", "FormatMessage", _
            "int", $FORMAT_MESSAGE_FROM_SYSTEM, _
            "ptr", 0, _
            "int", $ret[0], _
            "int", 0, _
            "ptr", DllStructGetPtr($p), _
            "int", 4096, _
            "ptr", 0)
    $s = DllStructGetData($p, 1)
    If $DisplayMsgBox <> "" Then MsgBox(0, "_GetLastErrorMessage", $DisplayMsgBox & @CRLF & $s)
    Return $s
EndFunc   ;==>_GetLastErrorMessage

SciTE for AutoItDirections for Submitting Standard UDFs

 

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

 

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