Disable BlockInput after 10 sec

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ozzii
Posts: 481
Joined: 30 Oct 2013, 06:04

Disable BlockInput after 10 sec

14 Mar 2017, 05:24

Hi,

In my script I have a BlockInput, on
But for example if my script is blocked between the BlockInput, on and BlockInput, off, I need to reboot my computer to regain accessibility.

So my question:
How to do to have the BlockInput active just for 10 seconds for example?
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Disable BlockInput after 10 sec

14 Mar 2017, 06:19

Add this function and its associated subroutine to your script. Then when you want to block input for 10 seconds, just call TimedBlockInput(10). Just make sure that if your program ends before the 10 seconds are up that you've turned BlockInput off before it exits.

Code: Select all

TimedBlockInput(seconds)
{
	BlockInput, On
	msec := 1000 * seconds
	SetTimer, BlockInputOff, -%msec%
}

BlockInputOff:
	BlockInput, Off
return
ozzii
Posts: 481
Joined: 30 Oct 2013, 06:04

Re: Disable BlockInput after 10 sec

14 Mar 2017, 17:45

Thanks boiler, I will test this tomorrow.
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: Disable BlockInput after 10 sec

15 Mar 2017, 01:28

ozzii wrote:I need to reboot my computer to regain accessibility.
Ctrl+Alt+Del should still work and let you close the script without rebooting ... ( win 7 tested )

Sry Boiler but I don't like labels =p

Code: Select all

TimedBlockInput(seconds, unblock := False) {
	if(unblock) {
		BlockInput Off
	}
	else {
		BlockInput On
		msec := 1000 * seconds
		fn := Func("TimedBlockInput").Bind(0, True)
		SetTimer % fn, -%msec%
	}
}
ozzii
Posts: 481
Joined: 30 Oct 2013, 06:04

Re: Disable BlockInput after 10 sec

15 Mar 2017, 03:17

Thanks,

I have a question.
When when I use this,

Code: Select all

TimedBlockInput(10)
TimedBlockInput(seconds)
{
	msgbox ,,,ON,1
	msec := 1000 * seconds
	SetTimer, BlockInputOff, -%msec%
}

BlockInputOff:
	msgbox ,,,OFF,1
	BlockInput, Off
return
the msgbox OFF appeared instantly after the ON.
I don't have my 10 seconds wait !
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Disable BlockInput after 10 sec

15 Mar 2017, 03:45

That's because you have not structured your code correctly by marking the end of your auto-execute section with a return (see documentation). So after it executed the function call, it proceeded to execute the next available line, which is the MsgBox after the BlockInputOff label.

You also need to let the program exist for at least 110 seconds after making the function call to give the timer a chance to complete the 10 second countdown. This is correctly structured and waits 15 seconds before ending the program.

Code: Select all

TimedBlockInput(10)
Sleep, 15000
return

TimedBlockInput(seconds)
{
	msgbox ,,,ON,1
	msec := 1000 * seconds
	SetTimer, BlockInputOff, -%msec%
}

BlockInputOff:
	msgbox ,,,OFF,1
	BlockInput, Off
return
Last edited by boiler on 15 Mar 2017, 04:00, edited 1 time in total.
ozzii
Posts: 481
Joined: 30 Oct 2013, 06:04

Re: Disable BlockInput after 10 sec

15 Mar 2017, 03:59

Already tried, but I have just the ON, no OFF message
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Disable BlockInput after 10 sec

15 Mar 2017, 04:01

See the edit above. Your program exits before 10 seconds are up.
ozzii
Posts: 481
Joined: 30 Oct 2013, 06:04

Re: Disable BlockInput after 10 sec

15 Mar 2017, 04:04

Thanks boiler for the explanation

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Joey5, RandomBoy and 368 guests