Sign in to follow this  
Followers 0

screen control script

18 posts in this topic

Posted

Hej,

This is my first posting. I searched the forum but am a little lost at present (I can do some programming but am not an IT expert or Windows programmer).

I stumbled upon autoit looking for a way to turn my laptop screen off, on and then off again with specific intervals at the push of a button, on WinXP. I have determined that this is apparently quite simple in *nix but want to use the current laptop.

So again: *press hotkey*

turn screen off

delay(1)

turn screen on

delay(2)

turn screen off

Then I should be able to turn the screen back on with the motion of the mouse, keyboard or hotkey

PS as a bonus but perhaps misdirected question for this forum:

* I want to check and ideally control the intensity of backlighting on my screen (i.e. the pwm if that is what's going on). This does not have to be from a script - just generally wondering how to check this.

* I want to make sure the backlight is completely off during the "off" state.

I have a PackBell ZG5, LED backlighting.

I am looking for a somewhat "quick and dirty" solution - although the following may be a good little project to start learning autoit.

Thanks!

Share this post


Link to post
Share on other sites



Posted (edited)

Thanks Mat, I turned that script around and post results below (not tested yet)

Just a couple of questions:

(1) are the values of the following universal on XP/Windows (hardware independent?):

Global Const $lciWM_SYSCommand = 274

Global Const $lciSC_MonitorPower = 61808

Global Const $lciPower_Off = 2

Global Const $lciPower_On = -1

(2) the sleep function takes an int as input. I assume this is seconds. Is there a function with msec resolution? How fast is typical response of the monitor/screen to on/off calls? How can I check this?

#NoTrayIcon
Global Const $lciWM_SYSCommand = 274
Global Const $lciSC_MonitorPower = 61808
Global Const $lciPower_Off = 2
Global Const $lciPower_On = -1
 
Global $MonitorIsOff = False
 
Global Const $Delay_1 = 1
 
 
HotKeySet("{F10}", "_Monitor_OFF")
HotKeySet("{F11}", "_Flicker")
HotKeySet("{Esc}", "_Quit")
 
MsgBox(64, "Monitor On/Off", "Press F10 to turn the monitor off." & @LF & _
	    "Press F11 to flicker." & @LF & _							
		"Press ESC to turn on the monitor and exit program.")
 
While 1	
	Sleep(10)
WEnd
 
 
Func _Flicker()	
	_Monitor_ON()
	Sleep($Delay_1)
	_Monitor_OFF()
EndFunc
 
 
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
Edited by umeaguy

Share this post


Link to post
Share on other sites

Posted

I'd like to add for anyone interested:

The idea is to generate "laptopograms": use my laptop screen to expose photosensitive paper. The paper can be quite sensitive, exposure times may need to be short. Also, I need to avoid background light and need strict control over screen illumination and exposure time.

Waste of time? Only if it's not fun!

I'll keep you posted if this works...

Share this post


Link to post
Share on other sites

Posted (edited)

They are always going to be the same, and can be found here.

Edit: waste of time? Time enjoyed wasting is not wasted time.

Edited by Mat

Share this post


Link to post
Share on other sites

Posted

umeaguy, your project sounds quite interesting, and the Sleep() function parameter is in milliseconds. At least, that what it says in the Help file (hint)(hint).

Share this post


Link to post
Share on other sites

Posted

Interesting concept.

Why even bother turning of your display at all?

I have a small Screen Cleaner app that I use which is essentially just a GUI with the popup style (Created slightly larger than the desktop) and a solid black background, triggered using hotkeys. So all you have to do is roll the mouse off-screen (in fact you can just hide the cursor) and then use hotkeys and timers to Show/Hide the GUI.

Share this post


Link to post
Share on other sites

Posted (edited)

Thanks Mat, that's clearer now. For future reference:

when calling DllCall, as in the following

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

the hex value "0x0112" equivalent to integer "274" refers to the (the method?) "WM_SYSCommand."

The $lciWM_SYSCommand is the constant placeholder for this numeric value.

Edited by umeaguy

Share this post


Link to post
Share on other sites

Posted

Hi GEOSoft, that may work - where can I get the cleaner to check it out?

It's important however that I have no background illumination at all - a "black" screen may still radiate significantly while on, particularly bad if the pixels are colored toward the blue/UV part of the spectrum instead of red (maybe a red screen would work better in fact as a "blank" background, as in a red darkroom light). I checked the "black" color generated by the screen using powerpoint: during a slide show the edges outside a slide are "black" but the pixels are clearly not "off" ie. there is some illumination, the color is closer to a very dark grey. This will produce what photographers call fog or even worse ruin the paper while not exposed to the image of interest. The idea is to expose for a fraction to a small number of seconds. My initial experiments suggest I have to keep exposures very short. I still have some kinks to work out but perhaps it'll turn out simpler than it currently looks.

Share this post


Link to post
Share on other sites

Posted (edited)

Just in case you decide to look at it again later here is the code I use for that Screen Cleaner.

HotKeySet("c", "_ToggleColor")
HotKeySet("{F1}", "_Help")
$bHelp = False
$bDark = True
$iColor = 1
HotKeySet("z", "_Cycle")
GUICreate("", @DesktopWidth +40, @DesktopHeight +40, -1, -1, 0x80000000, 0x00000008)
GUISetBkColor(0x000000)
$s_Label_Txt = "Press C to toggle between dark and light" & @CRLF &@CRLF & "Press Z to cycle through colors" & @CRLF & @CRLF & "Press {Esc} to Exit"
$lbl_Hlp = GUICtrlCreateLabel($s_Label_Txt, 120, 120, 350, 200)
GUICtrlSetColor($lbl_Hlp, 0xFFFFFF)
GUICtrlSetFont($lbl_Hlp, 12, 600)
GUICtrlSetState($lbl_Hlp, 32)
GUISetState()
While 1
If GUIGetMsg() = -3 Then Exit
WEnd
Func _Help()
$bHelp = NOT $bHelp
If $bHelp Then
  GUICtrlSetState($lbl_Hlp, 16)
Else
  GUICtrlSetState($lbl_Hlp, 32)
EndIf
EndFunc
Func _ToggleColor()
$bDark = NOT $bDark
If $bDark Then
  GUISetBkColor(0x000000)
  GUICtrlSetColor($lbl_Hlp, 0xFFFFFF)
Else
  GUISetBkColor(0xFFFFFF)
  GUICtrlSetColor($lbl_Hlp, 0x000000)
EndIf
EndFunc
 
Func _Cycle()
Local $iSet
Switch $iColor
  Case 1
   $iSet = 0xFF0000
   GUICtrlSetColor($lbl_Hlp, 0xFFFF00)
  Case 2
   $iSet = 0xFFFF00
   GUICtrlSetColor($lbl_Hlp, 0x000000)
  Case 3
   $iSet = 0x00FF00
   GUICtrlSetColor($lbl_Hlp, 0x000000)
  Case 4
   $iSet = 0xFF00FF
   GUICtrlSetColor($lbl_Hlp, 0x000000)
  Case 5
   $iSet = 0x0000FF
   GUICtrlSetColor($lbl_Hlp, 0xFFFFFF)
EndSwitch
$iColor += 1
If $iColor >= 6 Then $iColor = 1
GUISetBkColor($iSet)
EndFunc

Obviously you don't need any of the functions I have or the help label. All you would have to do is create it with Black and write a function to Show/Hide the GUI which would be called by a combination of your timers and a hotkey.

EDIT:

If you add the line

GUISetCursor(16)
just before the GUISetState() then it will hide the cursor for you so you don't have to worry about moving the mouse off screen at all. Edited by GEOSoft

Share this post


Link to post
Share on other sites

Posted

Thanks GEOSoft, I'll give this a shot ....

Share this post


Link to post
Share on other sites

Posted (edited)

No problem and I had a minute so I did up the code for you. Be sure to read the commented line at the top. and it's {F2} to show/hide the GUI.

;; To exit the script when it's hidden you just press Shift + {Esc}.  If the Window is active then {Esc} by itself will work.
HotKeySet("{F2}", "_Set_State")
HotKeySet("+{Esc}", "_Goodbye")
$bState = False
$Frm = GUICreate("", @DesktopWidth +40, @DesktopHeight +40, -1, -1, 0x80000000, 0x00000008)
GUISetBkColor(0x000000)
GUISetCursor(16)
While 1
	If GUIGetMsg() = -3 Then _Goodbye()
WEnd
 
Func _Set_State()
	$bState = NOT $bState
		If $bState Then
		  GUISetState(@SW_SHOW, $Frm)
		Else
		   GUISetState(@SW_HIDE, $Frm)
		EndIf
EndFunc
 
Func _Goodbye()
	Exit
EndFunc

Edit: Depending on what you are doing; you may want to set the screen color to White or use a function to switch it which would be the _ToggleColor() function in the first script. Remember to set the hotkey to handle it.

Edited by GEOSoft

Share this post


Link to post
Share on other sites

Posted (edited)

Thanks to everyone who provided feedback.

I managed to acquire my first (successful) laptopogram. Exposure time was 200 msec (thanks somdcomputerguy)

I ended up using the modified script I posted above which turns the screen on and off. The script from Geosoft worked but as I suspected there was still too much backlight wiith the screen on.

The execution of the script was a little glitchy (not responding always to the F10 and F11 keys as expected), probably due to conflicts with other software, and I was unable to display an image in full screen mode while running the script, but some modification would probably allow that.

Cheers!

Edited by umeaguy

Share this post


Link to post
Share on other sites

Posted

Thanks to everyone who provided feedback. I managed to acquire my first (successful) laptopogram. Exposure time was 200 msec (thanks somdcomputerguy)

Are you going to scan these and make the images 'publically viewable' somewhere? I look forward to seeing the results.

Share this post


Link to post
Share on other sites

Posted

I tried to post the image here but no luck.

I've posted a copy on flicker:

http://www.flickr.com/photos/68588636@N04/

Let me know if this doesn't work.

Share this post


Link to post
Share on other sites

Posted

@umeaguy

Hi neighbour!

Share this post


Link to post
Share on other sites

Posted

Hejsan!

Share this post


Link to post
Share on other sites

Posted

An update: this was so much fun I wanted to share it - it is now an instructable: http://www.instructables.com/id/Laptopogram/

If you have any suggestions on how to improve the script please let me know.

Thanks!

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