Sign in to follow this  
Followers 0
PhoenixXL

Idle Process UDF

15 posts in this topic

#1 ·  Posted (edited)

Code

#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 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.

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 :D

>"C:Program Files (x86)AutoIt3SciTE..autoit3.exe" /ErrorStdOut "D:DesktopNew AutoIt v3 Script.au3"

>Exit code: 0 Time: 5.105

Edited by IanN1990

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 :D now time to learn how the code works so i can use it

Edited by IanN1990

Share this post


Link to post
Share on other sites

This function can be found in WinAPIEx. So I would suggest looking at that instead. Search the forum for WinAPIEx.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thanks for the suggestion, i will look into it. Though i have already stripped the code and am intergerating it into my system :D

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 by IanN1990

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I would personally wrap in a function, then again I use WinAPIEx so no need. Also good code should support x64 too.

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Is there a simple way to modify this, that it would check for the idle time of specific program?

Share this post


Link to post
Share on other sites

idle time of specific program

If 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.

Share this post


Link to post
Share on other sites
:bye: 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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

This UDF has a specific purpose and would require a total re-write. Lets stick to one thread (the one MKISH linked.)

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • PhoenixXL
      By PhoenixXL
      HEy!! Every1

      I've made a UDF for a Func 2 Start whenever the computer gets Idle for the specified amount of time.........
      Hope that u find it helpful...........

      Any Modifications for betterment are welcomed..........

      Enjoy!!

      #cs #FUNCTION# ================================================================================================================= Name...........: _GetIdleTime() Description ...: (Can Execute A Function) When The User Is Idle For Specified Amount Of Time 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 ; =================================================================================================================