Jump to content
Sign in to follow this  

Keep Awake

Recommended Posts


If you're like me, you'll start writing essays at about 1am... By that time, people are prone to falling asleep, so I've knocked something up to help prevent that...

Global $lastact = 0
Global $_KEEPAWAKE = 2

Func _idletime(ByRef $lastact)
    $struct = DllStructCreate("uint;dword")
    DllStructSetData($struct, 1, DllStructGetSize($struct))
    DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct))
    If $lastact <> DllStructGetData($struct, 2) Then
        Local $prev = $lastact
        $lastact = DllStructGetData($struct, 2)
        Return $lastact - $prev

While 1
    $not_idle = _idletime($lastact)
    If $not_idle <> 0 Then $timer = TimerInit()
    If Int(TimerDiff($timer)/1000) > $_KEEPAWAKE Then
        Beep(500, 200)

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.