Trying to make a 5 min forced break timer Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Gate
Posts: 27
Joined: 31 Jan 2021, 20:00

Trying to make a 5 min forced break timer

05 Aug 2021, 10:20

My goal is to write a function which turns off the screen and disables inputs for a variable period of time. I'll put this on a loop to occur for 5 mins every hour, to force me to take a break from the computer lol. :problem:

The code doesn't actually disable the inputs though. Some of this code I researched so I don't fully understand it.

Code: Select all

ShutDownScreen(timeAsleep)
{
	Sleep 300 
	BlockInput, On ; Disable keyboard and mouse input (doesn't work)
	Sleep, 300 ; not sleeping will make it so your keyboard input wakes up the monitor immediately
	SendMessage 0x112, 0xF170, 2,,Program Manager ; send the monitor into off mode
	
	;wait for a key to be pressed or for timer
	if (timeAsleep)
		Sleep, %timeAsleep%
	else
		Input, SingleKey, F10, {LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{Capslock}{Numlock}{PrintScreen}{Pause} ; Not sure what this does, but the code I copied said 'wait for a key to be pressed'
	
	SendMessage 0x112, 0xF170, -1,,Program Manager ; send the monitor into on mode (doesn't work: something happens to the monitor, but it goes back off after)
	Sleep 300
	BlockInput, Off ; Enable keyboard and mouse input
	Sleep 300
	
	Sleep, 9
	MouseMove, 3, 3,,R ; This turns the monitor on
	Sleep, 9
}
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Trying to make a 5 min forced break timer  Topic is solved

05 Aug 2021, 11:02

My recollection is that in some situations, BlockInput requires running the script as admin. You could do a short test script that does nothing but blocks input for ten seconds, to see if that part works.
Gate
Posts: 27
Joined: 31 Jan 2021, 20:00

Re: Trying to make a 5 min forced break timer

05 Aug 2021, 16:19

Thanks, I did have to run as admin.

Here's what I ended up with if anyone in the future is curious.
(warning: it will make you unable to use your keyboard for 5 mins if you run as admin)

Code: Select all

Loop
{
	a := 55 * 60000
	Sleep, %a%
	Loop, 9
	{
		SoundSet, 100
		SoundBeep, 432, 600
		Sleep, 600
	}
	
	Sleep 300 
	BlockInput, On
	Sleep, 300 ; not sleeping will make it so your keyboard input wakes up the monitor immediately
	SendMessage 0x112, 0xF170, 2,,Program Manager ; send the monitor into off mode
	Sleep 300000
	BlockInput, Off
	Sleep 300
	
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: gongnl, RandomBoy, Rohwedder and 351 guests