Advertisement
Guest User

script

a guest
Oct 15th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.63 KB | None | 0 0
  1. #include <WinAPISys.au3>
  2.  
  3. Global Const $IDLETIME_GUID = '5816AA22-EEB4-4C92-BB07-4A5E1DBA4A6A'
  4. Global Enum $IDLETIME_DELEGATE, $IDLETIME_ID, $IDLETIME_ISRUNNING, $IDLETIME_TIME, $IDLETIME_MAX
  5.  
  6. Global $g_bIsRunning = True ; For the example only. This is set to false when ESC is pressed.
  7. HotKeySet('{ESC}', Close)
  8.  
  9. Example()
  10.  
  11. Func Example()
  12. Local $hIdle = _IdleTime(10000, WakeUp) ; Create an idle time object and set the time to move the mouse every 10 seconds and call the parameterless function WakeUp().
  13. ConsoleWrite('IsRunning: ' & _IdleTime_IsRunning($hIdle) & @CRLF) ; Display running status.
  14. ConsoleWrite('Time: ' & _IdleTime_GetTime($hIdle) & @CRLF)
  15.  
  16. _IdleTime_StopStartPause($hIdle) ; Start the idle time monitoring.
  17.  
  18. ConsoleWrite('IsRunning: ' & _IdleTime_IsRunning($hIdle) & @CRLF) ; Display running status.
  19.  
  20. While Sleep(250) And $g_bIsRunning
  21. WEnd
  22.  
  23. If _IdleTime_IsRunning($hIdle) Then
  24. _IdleTime_StopStartPause($hIdle) ; Stop if the idle time is currently running.
  25. EndIf
  26.  
  27. ConsoleWrite('IsRunning: ' & _IdleTime_IsRunning($hIdle) & @CRLF)
  28. Return True
  29. EndFunc ;==>Example
  30.  
  31. Func Close()
  32. $g_bIsRunning = False
  33. EndFunc ;==>Close
  34.  
  35. Func WakeUp()
  36. MsgBox($MB_SYSTEMMODAL, '', 'Please wake up!')
  37. EndFunc ;==>WakeUp
  38.  
  39. #Region IdleTime UDF
  40. Func _IdleTime($iTime = Default, $hFunc = Default)
  41. Local $aIdleTime[$IDLETIME_MAX]
  42. $aIdleTime[$IDLETIME_ID] = $IDLETIME_GUID
  43. $aIdleTime[$IDLETIME_ISRUNNING] = False
  44. __IdleTime_Delegate($aIdleTime, $hFunc) ; Set the delegate function. This should have no parameters.
  45. __IdleTime_Time($aIdleTime, $iTime) ; Set the time.
  46. Return $aIdleTime
  47. EndFunc ;==>_IdleTime
  48.  
  49. Func _IdleTime_GetDelegate(ByRef $aIdleTime)
  50. Return (__IdleTime_IsAPI($aIdleTime) ? $aIdleTime[$IDLETIME_DELEGATE] : Null)
  51. EndFunc ;==>_IdleTime_GetDelegate
  52.  
  53. Func _IdleTime_GetTime(ByRef $aIdleTime)
  54. Return (__IdleTime_IsAPI($aIdleTime) ? $aIdleTime[$IDLETIME_TIME] : Null)
  55. EndFunc ;==>_IdleTime_GetTime
  56.  
  57. Func _IdleTime_IsRunning(ByRef $aIdleTime)
  58. Return (__IdleTime_IsAPI($aIdleTime) ? $aIdleTime[$IDLETIME_ISRUNNING] : False)
  59. EndFunc ;==>_IdleTime_IsRunning
  60.  
  61. Func _IdleTime_SetDelegate(ByRef $aIdleTime, $hFunc)
  62. Local $bReturn = False
  63. If __IdleTime_IsAPI($aIdleTime) And __IdleTime_Time($aIdleTime, $hFunc) Then ; Set the delegate.
  64. $bReturn = True
  65. If _IdleTime_IsRunning($aIdleTime) Then
  66. _IdleTime_StopStartPause($aIdleTime) ; Stop.
  67. _IdleTime_StopStartPause($aIdleTime) ; Start.
  68. EndIf
  69. EndIf
  70. Return $bReturn
  71. EndFunc ;==>_IdleTime_SetDelegate
  72.  
  73. Func _IdleTime_SetTime(ByRef $aIdleTime, $iTime)
  74. Local $bReturn = False
  75. If __IdleTime_IsAPI($aIdleTime) And __IdleTime_Time($aIdleTime, $iTime) Then ; Set the time.
  76. $bReturn = True
  77. If _IdleTime_IsRunning($aIdleTime) Then
  78. _IdleTime_StopStartPause($aIdleTime) ; Stop.
  79. _IdleTime_StopStartPause($aIdleTime) ; Start.
  80. EndIf
  81. EndIf
  82. Return $bReturn
  83. EndFunc ;==>_IdleTime_SetTime
  84.  
  85. Func _IdleTime_StopStartPause(ByRef $aIdleTime)
  86. Local $bReturn = False
  87. If __IdleTime_IsAPI($aIdleTime) Then
  88. $bReturn = True
  89. If $aIdleTime[$IDLETIME_ISRUNNING] Then
  90. __IdleTime_Proc(0, 0) ; Set the static variablse in the procedure to the default of zero, thus clearing the previous values.
  91. AdlibUnRegister(__IdleTime_AdLibRegister)
  92. Else
  93. __IdleTime_Proc($aIdleTime[$IDLETIME_DELEGATE], $aIdleTime[$IDLETIME_TIME]) ; Set the static variables in the procedure to the required time when to move the mouse and delegate to call.
  94. AdlibRegister(__IdleTime_AdLibRegister, Ceiling($aIdleTime[$IDLETIME_TIME] / 3)) ; Register the function to be called time / 3.
  95. EndIf
  96. $aIdleTime[$IDLETIME_ISRUNNING] = Not $aIdleTime[$IDLETIME_ISRUNNING]
  97. EndIf
  98. Return $bReturn
  99. EndFunc ;==>_IdleTime_StopStartPause
  100.  
  101. Func __IdleTime_IsAPI(ByRef $aIdleTime)
  102. Return UBound($aIdleTime) = $IDLETIME_MAX And $aIdleTime[$IDLETIME_ID] = $IDLETIME_GUID
  103. EndFunc ;==>__IdleTime_IsAPI
  104.  
  105. Func __IdleTime_AdLibRegister() ; Wrapper for __IdleTime_Proc(), since AdLibRegister() doesn't accept functions with parameters.
  106. Return __IdleTime_Proc()
  107. EndFunc ;==>__IdleTime_AdLibRegister
  108.  
  109. Func __IdleTime_Delegate(ByRef $aIdleTime, $hFunc)
  110. If Not IsFunc($hFunc) Then $hFunc = 0
  111. $aIdleTime[$IDLETIME_DELEGATE] = $hFunc
  112. Return True
  113. EndFunc ;==>__IdleTime_Delegate
  114.  
  115. Func __IdleTime_Proc($hSetFunc = Default, $iSetTime = Default)
  116. Local Static $hFunc = 0, _
  117. $iTime = 0
  118. If $hSetFunc = Default And $iSetTime = Default And $iTime > 0 Then
  119. If _WinAPI_GetIdleTime() >= $iTime Then
  120. Local $aPos = MouseGetPos()
  121. If Not @error Then
  122. Local Enum $POS_X, $POS_Y
  123. MouseMove($aPos[$POS_X] + 1, $aPos[$POS_Y])
  124. MouseMove($aPos[$POS_X], $aPos[$POS_Y])
  125. If IsFunc($hFunc) Then ; Call a function if it's set.
  126. $hFunc()
  127. EndIf
  128. EndIf
  129. EndIf
  130. Else
  131. If Not ($hSetFunc = Default) Then $hFunc = $hSetFunc
  132. If Not ($iSetTime = Default) Then $iTime = $iSetTime
  133. EndIf
  134. Return True
  135. EndFunc ;==>__IdleTime_Proc
  136.  
  137. Func __IdleTime_Time(ByRef $aIdleTime, $iTime)
  138. If $iTime = Default Or $iTime < 750 Then $iTime = 750 ; 750 ms by default, since the procedure is checked 750 / 3 = 250 (which is the minimum for AdLibRegister()).
  139. $aIdleTime[$IDLETIME_TIME] = $iTime
  140. Return True
  141. EndFunc ;==>__IdleTime_Time
  142. #EndRegion IdleTime UDF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement