if any key is not pressed or mouse not moved

Get help with using AutoHotkey and its commands and hotkeys
genaro
Posts: 38
Joined: 09 Feb 2016, 20:07

if any key is not pressed or mouse not moved

14 Jan 2020, 23:46

Help me please. I want if any key is not pressed or mouse not moved for 5 seconds then script to save and close Notepad.
User avatar
telanx
Posts: 68
Joined: 10 Jan 2020, 14:31

Re: if any key is not pressed or mouse not moved

15 Jan 2020, 08:03

this, Title and time are a custom variable. :roll:

Code: Select all

SetTitleMatchMode 2

winTitle := "Notepad"
runTime := 5   ;mins
idleTime := 1   ;mins
startTime := A_TickCount

while A_TickCount-startTime < runTime*60*1000 {
    sleep 10000
    while WinExist(WinTitle) {
        if (A_TimeIdle > idleTime*60*1000) {
            ControlSend, , ^s, %WinTitle%
            sleep 2000
            WinClose %WinTitle%
            return
        }
    }
}
genaro
Posts: 38
Joined: 09 Feb 2016, 20:07

Re: if any key is not pressed or mouse not moved

03 Apr 2020, 18:35

telanx wrote:
15 Jan 2020, 08:03
this, Title and time are a custom variable. :roll:

Code: Select all

SetTitleMatchMode 2

winTitle := "Notepad"
runTime := 5   ;mins
idleTime := 1   ;mins
startTime := A_TickCount

while A_TickCount-startTime < runTime*60*1000 {
    sleep 10000
    while WinExist(WinTitle) {
        if (A_TimeIdle > idleTime*60*1000) {
            ControlSend, , ^s, %WinTitle%
            sleep 2000
            WinClose %WinTitle%
            return
        }
    }
}
I don't think it does what I want. I want it to close the text document if keyboard and mouse are not touched for 5 seconds.
Rohwedder
Posts: 3781
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: if any key is not pressed or mouse not moved

04 Apr 2020, 01:41

Hallo,
try:

Code: Select all

#Persistent
#InstallKeybdHook
#InstallMouseHook
SetTimer, Timer, 100
Timer:
IF A_TimeIdlePhysical < 5000
	Return
IF Win := WinExist("ahk_class #32770 ahk_exe NOTEPAD.EXE")
{
	WinActivate, ahk_id %Win%
	WinGetText, Text, ahk_id %Win%
	IF !InStr(Text,"*") ;no storage without file name!
		Send, {Return}
}
Else IF WinExist("ahk_exe NOTEPAD.EXE")
	WinClose
Return

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, HiSoKa, mikeyww, Ram, Weshuggah and 58 guests