Script Runs When NO Mouse Movement

Get help with using AutoHotkey and its commands and hotkeys
yabab33299
Posts: 98
Joined: 06 May 2020, 17:16

Script Runs When NO Mouse Movement

25 Jun 2020, 10:39

Hi, how do I make a script that runs a program or another script when there is no mouse movement after 5 minutes?
User avatar
boiler
Posts: 6823
Joined: 21 Dec 2014, 02:44

Re: Script Runs When NO Mouse Movement

25 Jun 2020, 10:46

Code: Select all

#Persistent
#InstallMouseHook

SetTimer, IdleCheck, 1000
return

IdleCheck:
	if (A_TimeIdleMouse > 300000)
		run notepad.exe
return
yabab33299
Posts: 98
Joined: 06 May 2020, 17:16

Re: Script Runs When NO Mouse Movement

25 Jun 2020, 11:13

boiler wrote:
25 Jun 2020, 10:46

Code: Select all

#Persistent
#InstallMouseHook

SetTimer, IdleCheck, 1000
return

IdleCheck:
	if (A_TimeIdleMouse > 300000)
		run notepad.exe
return
hi there. can you please explain installmousehook. I dont really get it in the tutorials
User avatar
boiler
Posts: 6823
Joined: 21 Dec 2014, 02:44

Re: Script Runs When NO Mouse Movement

25 Jun 2020, 11:21

It’s what’s needed for AHK to monitor mouse clicks and stuff, but since it takes a lot of memory, it doesn’t install it unless you have a mouse button as a hotkey or something. In this case, A_TimeIdleMouse won’t actually represent the idle time of the mouse unless the mouse hook is installed.
yabab33299
Posts: 98
Joined: 06 May 2020, 17:16

Re: Script Runs When NO Mouse Movement

25 Jun 2020, 12:03

boiler wrote:
25 Jun 2020, 11:21
It’s what’s needed for AHK to monitor mouse clicks and stuff, but since it takes a lot of memory, it doesn’t install it unless you have a mouse button as a hotkey or something. In this case, A_TimeIdleMouse won’t actually represent the idle time of the mouse unless the mouse hook is installed.
Also, what does the 1000 mean in "SetTimer, IdleCheck, 1000"?
User avatar
boiler
Posts: 6823
Joined: 21 Dec 2014, 02:44

Re: Script Runs When NO Mouse Movement

25 Jun 2020, 14:36

It means that it runs that subroutine every 1000 ms, which is 1 second.

In general, it is helpful in learning AHK to look up commands and see what the parameters mean. You can click on SetTimer in the posted script, and it will open that page in the documentation.
yabab33299
Posts: 98
Joined: 06 May 2020, 17:16

Re: Script Runs When NO Mouse Movement

25 Jun 2020, 19:52

boiler wrote:
25 Jun 2020, 10:46

Code: Select all

#Persistent
#InstallMouseHook

SetTimer, IdleCheck, 1000
return

IdleCheck:
	if (A_TimeIdleMouse > 300000)
		run notepad.exe
return
Your script keeps looping, when the 5 min mark is reached, it keeps popping out many notepad.exe. I had to move the mouse to stop it, but then after the 5 min IDLE, it keeps doing the same thing.
Last edited by yabab33299 on 25 Jun 2020, 20:22, edited 1 time in total.
User avatar
boiler
Posts: 6823
Joined: 21 Dec 2014, 02:44

Re: Script Runs When NO Mouse Movement

25 Jun 2020, 20:22

Code: Select all

#Persistent
#InstallMouseHook

SetTimer, IdleCheck, 1000
return

IdleCheck:
	if (A_TimeIdleMouse > 300000) {
		run notepad.exe
		ExitApp
	}
return
yabab33299
Posts: 98
Joined: 06 May 2020, 17:16

Re: Script Runs When NO Mouse Movement

25 Jun 2020, 20:32

boiler wrote:
25 Jun 2020, 20:22

Code: Select all

#Persistent
#InstallMouseHook

SetTimer, IdleCheck, 1000
return

IdleCheck:
	if (A_TimeIdleMouse > 300000) {
		run notepad.exe
		ExitApp
	}
return
This script exits out. Can you please be so kind to customize the script to be persistent throughout, and the script restarts the countdown to 5 min IDLE when the mouse is moved. Thankyou very much.
User avatar
boiler
Posts: 6823
Joined: 21 Dec 2014, 02:44

Re: Script Runs When NO Mouse Movement

25 Jun 2020, 20:46

It automatically starts the 5 minute count again when the mouse is moved. What do do you want it to do after it runs the program? Not run it again if it is already open even if another 5 minutes of inactivity occurs? That would be this:

Code: Select all

#Persistent
#InstallMouseHook

SetTimer, IdleCheck, 1000
return

IdleCheck:
	if (A_TimeIdleMouse > 300000) && !WinExist("ahk_exe notepad.exe")
		run notepad.exe
return
yabab33299
Posts: 98
Joined: 06 May 2020, 17:16

Re: Script Runs When NO Mouse Movement

26 Jun 2020, 11:23

boiler wrote:
25 Jun 2020, 20:46

#InstallMouseHook
Hi, I was wondering is that a way to make an autohotkey script or its compiled version to start when windows boots or when user logs in?
User avatar
boiler
Posts: 6823
Joined: 21 Dec 2014, 02:44

Re: Script Runs When NO Mouse Movement

26 Jun 2020, 12:06

Right-click on the script file in file explorer and select "Create shortcut" from the menu. Then move or copy that shortcut file (not the original file) into your Windows Startup folder, which should be C:\Users\<user name>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.
RickC
Posts: 253
Joined: 27 Oct 2013, 08:32

Re: Script Runs When NO Mouse Movement

25 Jul 2020, 23:42

Or, if you need your script/program to start earlier in the boot process (for example, to run Process Monitor to watch login events), use 'run as TaskMan'. It's a registry location that runs a value (executable) assigned to a Taskman entry in the context of WINLOGON, i.e. even before Explorer waits for the Service Control Manager to initialise. You need to create the 'Taskman' entry because it's not there by default.

So, if - for arguments sake - I wanted to run WordPad early in the boot process, I could set it using a REG file or AutoHotkey to write the required registry entry/value pair:

Code: Select all

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
"Taskman"="C:\\Windows\\write.exe"


Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], LeonAskin, wineguy, yoooooo and 62 guests