Sleep In The Corner (Monitor Off)

By raccoon on Mar 25, 2013

Simple script that puts your monitors to sleep or keeps your monitors awake, depending on which corner of the screen you leave your mouse.

Modify it to your liking.

  • Raccoon
; Put your monitors to sleep by moving your mouse to the bottom-right corner of your 
; primary desktop for 5 seconds.  (Ie: over Show Desktop (win7) or 16x16 pixels)
; Keep your monitors awake (bypass power savings) by keeping your mouse in the
; bottom-left corner of your primary desktop.  (Ie: over Start Button or 16x16 pixels)

#SingleInstance Force
#Persistent
SetTimer, EverySecond, 1000
RETURN

EverySecond:
  ScreenSleepCorner(5000) ; 5 Second Delay
  ScreenWakeCorner(55000) ; 55 Second Repeat
  Return

; Move your mouse to the bottom-right corner of your desktop to Sleep.
; (Either over the Show Desktop button or 16x16 pixel corner)
ScreenSleepCorner(Delay := 5000) ; By Raccoon 2013
{
  Static IsAsleep := 0
  if (A_TimeIdle >= Delay) && (IsAsleep == 0) {
    CoordMode, Mouse, Screen
    MouseGetPos, mX, mY, hWnd, hCtrl
    if (hCtrl == "TrayShowDesktopButtonWClass1")
    || ( (A_ScreenWidth  - mX < 16) && (A_ScreenWidth  - mX >= 0)
      && (A_ScreenHeight - mY < 16) && (A_ScreenHeight - mY >= 0)) {
      IsAsleep := 1
      SendMessage,0x112,0xF170,2,,A ; Sleep Monitors
    }
  }
  else if (A_TimeIdle < Delay) && (IsAsleep == 1) {
    IsAsleep := 0
    CoordMode, Mouse, Screen
    MouseMove, % A_ScreenWidth / 2, % A_ScreenHeight / 2 ; Center Mouse
  }
}

; Move your mouse to the bottom-left corner of your desktop to Keep Awake.
; (Either over the Start Menu button or 16x16 pixel corner)
ScreenWakeCorner(Delay := 55000) ; By Raccoon 2013
{
  if (A_TimeIdle >= Delay) {
    CoordMode, Mouse, Screen
    MouseGetPos, mX, mY, hWnd, hCtrl
    WinGetTitle, sTitle, ahk_id %hWnd%
    WinGetClass, sClass, ahk_id %hWnd%
    ; tooltip % sTitle " - " sClass " - " A_TimeIdle
    if (sTitle == "Start") && (sClass == "Button")
    || ( (mX < 16) && (mX >= 0)
      && (A_ScreenHeight - mY < 16) && (A_ScreenHeight - mY >= 0)) {
      MouseMove, 1, 1, 0, R
      MouseMove, -1, -1, 0, R
    }
  }
}

Comments

Sign in to comment.
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.