Guest User

_PowerKeepAlive.au3

a guest
Jun 9th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.77 KB | None | 0 0
  1. #include-once
  2. ; ===============================================================================================================================
  3. ; <_PowerKeepAlive.au3>
  4. ;
  5. ; Functions to prevent/disable sleep/power-savings modes (AND screensaver)
  6. ;
  7. ; Functions:
  8. ;    _PowerKeepAlive()
  9. ;    _PowerResetState()
  10. ;
  11. ; See also:
  12. ;    <_ScreenSaverFunctions.au3>    ; query, change, enable & disable screensaver.
  13. ;
  14. ; Author: Ascend4nt
  15. ; ===============================================================================================================================
  16.  
  17. ; ==========================================================================================================================
  18. ; Func _PowerKeepAlive()
  19. ;
  20. ; Function to Prevent the Screensaver and Sleep/Power-savings modes from kicking in.
  21. ;    NOTE: Be sure to reset this state on exit!
  22. ;
  23. ; Returns:
  24. ;    Success: @error=0 & previous state as # (typically 0x80000000 [-2147483648])
  25. ;    Failure: @error set (returns 0x80000000, but thats just the normal state)
  26. ;        @error = 2 = DLLCall error. @extended = DLLCall error code (see AutoIt Help)
  27. ;
  28. ; Author: Ascend4nt
  29. ; ==========================================================================================================================
  30.  
  31. Func _PowerKeepAlive()
  32. #cs
  33.     ; Flags:
  34.     ;    ES_SYSTEM_REQUIRED  (0x01) -> Resets system Idle timer
  35.     ;    ES_DISPLAY_REQUIRED (0x02) -> Resets display Idle timer
  36.     ;    ES_CONTINUOUS (0x80000000) -> Forces 'continuous mode' -> the above 2 will not need to continuously be reset
  37. #ce
  38.     Local $aRet=DllCall('kernel32.dll','long','SetThreadExecutionState','long',0x80000003)
  39.     If @error Then Return SetError(2,@error,0x80000000)
  40.     Return $aRet[0]    ; Previous state (typically 0x80000000 [-2147483648])
  41. EndFunc
  42.  
  43. ; ==========================================================================================================================
  44. ; Func _PowerResetState()
  45. ;
  46. ; Function to Reset the Screensaver and Sleep/Power-savings modes to defaults.
  47. ;    NOTE: The timer is reset on each call to this!
  48. ;
  49. ; Returns:
  50. ;    Success: @error=0 & previous state as #
  51. ;    Failure: @error set (returns 0x80000000, but thats just the normal state)
  52. ;        @error = 2 = DLLCall error. @extended = DLLCall error code (see AutoIt Help)
  53. ;
  54. ; Author: Ascend4nt
  55. ; ==========================================================================================================================
  56.  
  57. Func _PowerResetState()
  58.     ; Flag:    ES_CONTINUOUS (0x80000000) -> (default) -> used alone, it resets timers & allows regular sleep/power-savings mode
  59.     Local $aRet=DllCall('kernel32.dll','long','SetThreadExecutionState','long',0x80000000)
  60.     If @error Then Return SetError(2,@error,0x80000000)
  61.     Return $aRet[0]    ; Previous state
  62. EndFunc
Add Comment
Please, Sign In to add comment