Sign in to follow this  
Followers 0
dromenox

Turn screen on/off

3 posts in this topic

I need some things to be running on my laptop at night and want to turn off the screen to avoid problems with the video. I found this script that does what I want. It works well, but if I get enough time with the screen off the screen does not turn on anymore and I have to force shut down the notebook.
 
Does anyone have any idea what I can do to not have this problem?
 
Global Const $lciWM_SYSCommand = 274
Global Const $lciSC_MonitorPower = 61808
Global Const $lciPower_Off = 2
Global Const $lciPower_On = -1
Global $MonitorIsOff = False

HotKeySet("{F11}", "_Monitor_OFF")
HotKeySet("{F10}", "_Monitor_ON")
HotKeySet("{Esc}", "_Quit")

While 1
   Sleep(10)
WEnd

Func _Monitor_ON()
    $MonitorIsOff = False
    Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]')

    DllCall('user32.dll', 'int', 'SendMessage', _
                                                'hwnd', $Progman_hwnd, _
                                                'int', $lciWM_SYSCommand, _
                                                'int', $lciSC_MonitorPower, _
                                                'int', $lciPower_On)
EndFunc

Func _Monitor_OFF()
    $MonitorIsOff = True
    Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]')

    While $MonitorIsOff = True
        DllCall('user32.dll', 'int', 'SendMessage', _
                                                    'hwnd', $Progman_hwnd, _
                                                    'int', $lciWM_SYSCommand, _
                                                    'int', $lciSC_MonitorPower, _
                                                    'int', $lciPower_Off)
        _IdleWaitCommit(0)
        Sleep(20)
    WEnd
EndFunc

Func _IdleWaitCommit($idlesec)
    Local $iSave, $LastInputInfo = DllStructCreate ("uint;dword")
    DllStructSetData ($LastInputInfo, 1, DllStructGetSize ($LastInputInfo))
    DllCall ("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr ($LastInputInfo))
    Do
        $iSave = DllStructGetData ($LastInputInfo, 2)
        Sleep(60)
        DllCall ("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr ($LastInputInfo))
    Until (DllStructGetData ($LastInputInfo, 2)-$iSave) > $idlesec Or $MonitorIsOff = False
    Return DllStructGetData ($LastInputInfo, 2)-$iSave
EndFunc

Func _Quit()
    _Monitor_ON()
    Exit
EndFunc

 

Share this post


Link to post
Share on other sites



Shut the lid, but turn off the power option that puts the laptop to sleep when you do that.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You should just find the option for the laptop to do nothing when the lid is shut.  Setting your laptop to this option will still turn the screen off, but will leave the computer running as usual (you can check this by peeking at the screen with the lid closed almost all the way).  You can also play a YouTube video and close the lid to verify that the laptop is on.  I can show you how to change this setting on Windows 7 below:

1. Open "Control Panel".

2. Go to "Hardware and Sound".

3. Click on "Power Options".

4. Then go to  "Choose what closing the lid does".  ( this can be found on the menu on the left side of the window)

5. From here, you can set the option for the laptop to do nothing when the lid is closed (from the drop-down menu that should be defaulted to "sleep".

Enjoy! I hope that I helped.  :bye:

P.S. Alternatively, there are programs that turn your screen off.  I have used a program called "Turn Off Monitor" that works well.  However, you should note that these programs will typically turn the screen back on when they detect activity such as the mouse moving or the pressing of a button.

Edited by JSBach

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