PhoenixXL Posted April 7, 2012 Posted April 7, 2012 (edited) Codeexpandcollapse popup#cs #FUNCTION# ==================================================================================================================== Name...........: _GetIdleTime() Description ...: (Can Execute A Function) When The User Is Idle For Specified Amount Of Time or Vice-Versa Syntax.........: _GetIdleTime($Time,$Return=0) Parameters ....: $Time = The Amount Of Time to Check The User To be Idle.... $Return = 1 Return The Func Immediately if The User is not Idle $Return = 0 Wait For The User To Get Idle For Specified Amount of Time and Then Return Returns........: Success = 0 Failure(The User Wasnt Idle For The Specified Amount of Time , Applicable only When $Return=1) = 1 Unable To call User32.dll = -1 Unable To create Dll Structure = -2 Author ........: Abhishek Remarks .......: To Execute a Func When The User is Not Idle Call a Func in [Section] Example .......: _Example() #ce =============================================================================================================================== Func _GetIdleTime($Time,$Return=0) Local $ISAVE, $LASTINPUTINFO = DllStructCreate("uint;dword"), $TRACE = 0 If $LASTINPUTINFO=0 Then Return -2 DllStructSetData($LASTINPUTINFO, 1, DllStructGetSize($LASTINPUTINFO)) DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($LASTINPUTINFO)) If @error Then Return -1 While $TRACE <= $Time $ISAVE = DllStructGetData($LASTINPUTINFO, 2) Sleep(1000) DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($LASTINPUTINFO)) Switch Floor(DllStructGetData($LASTINPUTINFO, 2) / 1000) - Floor($ISAVE / 1000) Case 0 $TRACE += 1 Case Else $TRACE = 0 Switch $Return Case 0 ;[Section] Stuff to do when the user is not Idle Case 1 Return 1 EndSwitch EndSwitch WEnd ;Call($FuncName) ;Stuff to do when the user is Idle for the specified amount of time Return 0 EndFunc ; =============================================================================================================================== _Example() Func _Example() Sleep(5000) Switch _GetIdleTime(10,1) Case 0 MsgBox(0,"Information",'The User Was Idle For 10 Secs.......') Case 1 MsgBox(0,"Information","The User Wasn't Idle For 10 Secs.......") EndSwitch EndFunc ; =============================================================================================================================== Edited October 29, 2012 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.
Newb Posted April 9, 2012 Posted April 9, 2012 Good, but can't this be just done with a TimerInit/TimerDiff which are already built in? (or also a Sleep, if you want to do it the rude way) Btw, if your aim was to do it without timer functions, good work, i could learn something from there. I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.
Newb Posted April 11, 2012 Posted April 11, 2012 Thanks to you for sharing with us I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.
IanN1990 Posted August 14, 2012 Posted August 14, 2012 (edited) I just tryed the code on my pc and it doesn't work. WIndows 7 Proffesional N (64 Bit) No Error Messages. Just...nothing >"C:Program Files (x86)AutoIt3SciTE..autoit3.exe" /ErrorStdOut "D:DesktopNew AutoIt v3 Script.au3" >Exit code: 0 Time: 5.105 Edited August 14, 2012 by IanN1990
PhoenixXL Posted August 15, 2012 Author Posted August 15, 2012 Can you give the code? My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.
IanN1990 Posted August 15, 2012 Posted August 15, 2012 (edited) The code i tryed, is the code you provided in the orginal post of this topic **Edit This is my fault. My Autoit by default runs in X64 to prevent crashes with other code i use. Seams this code only works with X32. Sorry for the Confusion. Have given 5 stars Main reason i was intereseted with this UDF is because i needed some code to detect when IDLE is broken on a pc, to lock it. Using the built-into autoit one, it detects when my wirelss mouse turns off as a "idle breaker" whereas this code doesnt now time to learn how the code works so i can use it Edited August 15, 2012 by IanN1990
guinness Posted August 15, 2012 Posted August 15, 2012 This function can be found in WinAPIEx. So I would suggest looking at that instead. Search the forum for WinAPIEx. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
IanN1990 Posted August 15, 2012 Posted August 15, 2012 (edited) Thanks for the suggestion, i will look into it. Though i have already stripped the code and am intergerating it into my system Local $ISAVE, $LASTINPUTINFO = DllStructCreate("uint;dword"), $TRACE = 0 DllStructSetData($LASTINPUTINFO, 1, DllStructGetSize($LASTINPUTINFO)) DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($LASTINPUTINFO)) While True $ISAVE = DllStructGetData($LASTINPUTINFO, 2) Sleep(250) DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($LASTINPUTINFO)) Switch Floor(DllStructGetData($LASTINPUTINFO, 2) / 1000) - Floor($ISAVE / 1000) Case 0 $TRACE += 1 Case Else $TRACE = 0 ConsoleWrite("A") EndSwitch WEnd Does the job perfectly Once run any movement of the mouse or push of a key. It detects it has happened, and writes A Edited August 15, 2012 by IanN1990
guinness Posted August 15, 2012 Posted August 15, 2012 (edited) I would personally wrap in a function, then again I use WinAPIEx so no need. Also good code should support x64 too. Edited August 15, 2012 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
IanN1990 Posted August 15, 2012 Posted August 15, 2012 The code i tryed in the orginal post, i ran ino autoit and displayed the post. It just exited after 5 seconds. When trying it with the 32bit, it worked fine. After stripping the code and intergating it into my system code. It works on both 32 and 64. So yea. I cant explain it, maybe my pc is just weird ^^ In any event i am happy i found this topic as its allowed me to replace my old code using _Timer_GetIdleTime which didn't really work very well.
Damodara Posted November 22, 2012 Posted November 22, 2012 Is there a simple way to modify this, that it would check for the idle time of specific program?
PhoenixXL Posted November 23, 2012 Author Posted November 23, 2012 idle time of specific programIf you want to track the Keyboard and Mouse input for a specific program then its not simple My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.
stormbreaker Posted November 23, 2012 Posted November 23, 2012 Damodara, I believe you already got help for this: ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1
PhoenixXL Posted November 23, 2012 Author Posted November 23, 2012 Damodara, Please give more details You want to get the UserInput [Keyboard Mouse] or the Focus My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.
guinness Posted November 23, 2012 Posted November 23, 2012 (edited) This UDF has a specific purpose and would require a total re-write. Lets stick to one thread (the one MKISH linked.) Edited November 23, 2012 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
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