PsaltyDS Posted April 28, 2008 Posted April 28, 2008 (edited) This function returns the time (in ticks) since the last user action with mouse/keyboard. Info on the first DLL call for GetLastInputInfo came from a post by GaryFrost. This method does not require a call to the function for "initializing" before gettting the user idle time, which is why I prefer it to _CheckIdle().The second call to convert the time is lifted from _Date_Time_GetTickCount(). Seems to work pretty well. Constructive critique is always welcome.Here's the function: expandcollapse popup; #FUNCTION#;=============================================================================== ; ; Name...........: _Timer_GetIdleTime() ; Description ...: Returns the number of ticks since last user activity (i.e. KYBD/Mouse) ; Syntax.........: _Timer_GetIdleTime() ; Parameters ....: None ; Return values .: Success - integer ticks since last (approx. milliseconds) since last activity ; Failure - Sets @extended = 1 if rollover occurs (see remarks) ; Author ........: PsaltyDS at http://www.autoitscript.com/forum ; Modified.......: v1.0.0 -- 03/20/2008 First version ; v1.0.1 -- 06/11/2008 Fixed bug when idle time = 0ms ; Remarks .......: The current ticks since last system restart will roll over to 0 every 50 days or so, ; which makes it possible for last user activity to be before the rollover, but run time ; of this function to be after the rollover. If this happens, @extended = 1 and the ; returned value is ticks since rollover occured. ; Related .......: _CheckIdle() ; Link ..........; ; Example .......; Yes ; ;;========================================================================================== Func _Timer_GetIdleTime() ; Get ticks at last activity Local $tStruct = DllStructCreate("uint;dword"); DllStructSetData($tStruct, 1, DllStructGetSize($tStruct)); DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($tStruct)) ; Get current ticks since last restart Local $avTicks = DllCall("Kernel32.dll", "int", "GetTickCount") ; Return time since last activity, in ticks (approx milliseconds) Local $iDiff = $avTicks[0] - DllStructGetData($tStruct, 2) If $iDiff >= 0 Then ; Normal return Return $iDiff Else ; Rollover of ticks counter has occured Return SetError(0, 1, $avTicks[0]) EndIf EndFunc ;==>_Timer_GetIdleTime...and here's the demo script: ; _Timer_GetIdleTime.au3 #include <Timers.au3> ; Mouse/Keyboard action during this 10 sec delay will change reported idle time Sleep(10 * 1000); 10sec Global $iIdleTime = _Timer_GetIdleTime() MsgBox(64, "_Timer_GetIdleTime", "Idle time = " & $iIdleTime & "ms") Edit: v1.0.1 Fixed bug reported by FitzChivalryEdit: Reformatted for submission as a UDF. Edited June 18, 2008 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
monoceres Posted April 28, 2008 Posted April 28, 2008 This one is a keeper! Thanks very much Broken link? PM me and I'll send you the file!
Skrip Posted April 29, 2008 Posted April 29, 2008 Very nice! This will be good. [left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]
PsaltyDS Posted June 11, 2008 Author Posted June 11, 2008 v1.0.1 posted after FitzChivalry found bug where idle time is 0. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
PsaltyDS Posted June 18, 2008 Author Posted June 18, 2008 Reformatted for submission as a possible addition to the Timers.au3 UDF. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
PsaltyDS Posted June 23, 2008 Author Posted June 23, 2008 The Timers.au3 UDF includes _Timer_GetIdleTime() as of Beta 3.2.13.3 dated 6/22/08. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
jaweb Posted August 12, 2010 Posted August 12, 2010 (edited) This function returns the time (in ticks) since the last user action with mouse/keyboard. Info on the first DLL call for GetLastInputInfo came from a post by GaryFrost. This method does not require a call to the function for "initializing" before gettting the user idle time, which is why I prefer it to _CheckIdle(). The second call to convert the time is lifted from _Date_Time_GetTickCount(). Seems to work pretty well. Constructive critique is always welcome. Here's the function: expandcollapse popup; #FUNCTION#;=============================================================================== ; ; Name...........: _Timer_GetIdleTime() ; Description ...: Returns the number of ticks since last user activity (i.e. KYBD/Mouse) ; Syntax.........: _Timer_GetIdleTime() ; Parameters ....: None ; Return values .: Success - integer ticks since last (approx. milliseconds) since last activity ; Failure - Sets @extended = 1 if rollover occurs (see remarks) ; Author ........: PsaltyDS at http://www.autoitscript.com/forum ; Modified.......: v1.0.0 -- 03/20/2008 First version ; v1.0.1 -- 06/11/2008 Fixed bug when idle time = 0ms ; Remarks .......: The current ticks since last system restart will roll over to 0 every 50 days or so, ; which makes it possible for last user activity to be before the rollover, but run time ; of this function to be after the rollover. If this happens, @extended = 1 and the ; returned value is ticks since rollover occured. ; Related .......: _CheckIdle() ; Link ..........; ; Example .......; Yes ; ;;========================================================================================== Func _Timer_GetIdleTime() ; Get ticks at last activity Local $tStruct = DllStructCreate("uint;dword"); DllStructSetData($tStruct, 1, DllStructGetSize($tStruct)); DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($tStruct)) ; Get current ticks since last restart Local $avTicks = DllCall("Kernel32.dll", "int", "GetTickCount") ; Return time since last activity, in ticks (approx milliseconds) Local $iDiff = $avTicks[0] - DllStructGetData($tStruct, 2) If $iDiff >= 0 Then ; Normal return Return $iDiff Else ; Rollover of ticks counter has occured Return SetError(0, 1, $avTicks[0]) EndIf EndFunc ;==>_Timer_GetIdleTime ...and here's the demo script: ; _Timer_GetIdleTime.au3 #include <Timers.au3> ; Mouse/Keyboard action during this 10 sec delay will change reported idle time Sleep(10 * 1000); 10sec Global $iIdleTime = _Timer_GetIdleTime() MsgBox(64, "_Timer_GetIdleTime", "Idle time = " & $iIdleTime & "ms") Edit: v1.0.1 Fixed bug reported by FitzChivalry Edit: Reformatted for submission as a UDF. How to insert this into a script? Replace the MsgBox with the script? Edited August 12, 2010 by jaweb
PsaltyDS Posted August 12, 2010 Author Posted August 12, 2010 The minimum you need is one line for the #include, and one line to call the function: #include <Timers.au3> Global $iIdleTime = _Timer_GetIdleTime() Now do as you please with the value in $iIdleTime. You can call the function anywhere in your script. The place to do it depends entirely on what your script is doing. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
jaweb Posted August 12, 2010 Posted August 12, 2010 I'm making a prank script. Where to insert so it runs when idle. Can you also explain as if you're talking to a child. #NoTrayIcon #include <IE.au3> while 1 $oIE = _IECreate() $hIE = _IEPropertyGet($oIE, "hwnd") WinSetState($hIE, "", @SW_MAXIMIZE) _IENavigate($oIE, "https://secure.wikimedia.org/wikipedia/en/wiki/Artificial_intelligence") _IELoadWait ($oIE) MouseClick("left",Random(100,500,1),Random(100,500,1)) Sleep(2000) _IELoadWait ($oIE) MouseClick("left",Random(100,500,1),Random(100,500,1)) Sleep(2000) _IELoadWait ($oIE) MouseClick("left",Random(100,500,1),Random(100,500,1)) Sleep(2000) _IELoadWait ($oIE) $PID = ProcessExists("IEXPLORE.EXE") ; Will return the PID or 0 if the process isn't found. If $PID Then ProcessClose($PID) _IEQuit ($oIE) Sleep(Random(60000,70000)) WEnd
PsaltyDS Posted August 12, 2010 Author Posted August 12, 2010 I'm making a prank script... Can you also explain as if you're talking to a child.It seems I am. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
AndreyS Posted November 29, 2012 Posted November 29, 2012 Dear professionals, tell me, please, why _Timer_GetIdleTime() function does not work when the wireless headset? Can I fix it somehow?
BrewManNH Posted November 29, 2012 Posted November 29, 2012 It's a headset, it's not a mouse or keyboard, does it wake your computer from the screensaver if you use it? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
AndreyS Posted November 29, 2012 Posted November 29, 2012 (edited) It is interesting that the screen saver continues to work with the headset, but the function ceases. And the messenger program also comes from "away." If it helps somehow, the model is a wireless headset: Rapoo H8020. Another issue here is associated with it: Perhaps there is a connection in this?! Edited November 29, 2012 by AndreyS
BrewManNH Posted November 29, 2012 Posted November 29, 2012 I'm not sure what your problem is with the function and your headset. What is it you're trying to accomplish with this that isn't working correctly with your headset? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
AndreyS Posted November 30, 2012 Posted November 30, 2012 (edited) Explain! I have a program designed to Autoit that depend on the function _Timer_GetIdleTime (). But if the headset works, the function always returns about 16ms. If you turn off the headset is idle time is right. Thus, when the function is working headset _Timer_GetIdleTime () does not consider the time of computer inactivity. On the headset because I do not press any buttons at the same time! But the screensaver works with the headset on! How can I fix this in the _Timer_GetIdleTime () to make it work with the headset? I would be very grateful! Edited November 30, 2012 by AndreyS
AndreyS Posted December 10, 2012 Posted December 10, 2012 So can anyone tell me at least how to change the function _Timer_GetIdleTime() (Timers.au3) that it does not respond to mouse movements?
BrewManNH Posted December 10, 2012 Posted December 10, 2012 You can't, it monitors activity, and using the mouse is activity. You'd need to do it another way to have it not monitor the mouse. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
AndreyS Posted December 10, 2012 Posted December 10, 2012 Yes, yes! But how? Can tell me? I think if it is possible to track only pressing a button keyboard and mouse, it will work with my headset.
BrewManNH Posted December 10, 2012 Posted December 10, 2012 I can only think of using _IsPressed, or something similar, to detect when a key is pressed either on the keyboard or the mouse, and resetting a timer if it detects one or the other. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
AndreyS Posted December 10, 2012 Posted December 10, 2012 I just started thinking about this but so far no ideas.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now