umeaguy Posted October 11, 2011 Posted October 11, 2011 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!
Mat Posted October 11, 2011 Posted October 11, 2011 This looks about right: http://autoitscript.com/forum/topic/57559-monitor-onoff-example/ AutoIt Project Listing
umeaguy Posted October 11, 2011 Author Posted October 11, 2011 (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? expandcollapse popup#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 October 11, 2011 by umeaguy
umeaguy Posted October 11, 2011 Author Posted October 11, 2011 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...
Mat Posted October 11, 2011 Posted October 11, 2011 (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 October 11, 2011 by Mat AutoIt Project Listing
somdcomputerguy Posted October 11, 2011 Posted October 11, 2011 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). - Bruce /*somdcomputerguy */Â If you change the way you look at things, the things you look at change.
GEOSoft Posted October 11, 2011 Posted October 11, 2011 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. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
umeaguy Posted October 11, 2011 Author Posted October 11, 2011 (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 October 11, 2011 by umeaguy
umeaguy Posted October 11, 2011 Author Posted October 11, 2011 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.
GEOSoft Posted October 11, 2011 Posted October 11, 2011 (edited) Just in case you decide to look at it again later here is the code I use for that Screen Cleaner. expandcollapse popupHotKeySet("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 October 11, 2011 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
umeaguy Posted October 11, 2011 Author Posted October 11, 2011 Thanks GEOSoft, I'll give this a shot ....
GEOSoft Posted October 11, 2011 Posted October 11, 2011 (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 October 11, 2011 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
umeaguy Posted October 11, 2011 Author Posted October 11, 2011 (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 October 11, 2011 by umeaguy
somdcomputerguy Posted October 12, 2011 Posted October 12, 2011 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. - Bruce /*somdcomputerguy */Â If you change the way you look at things, the things you look at change.
umeaguy Posted October 12, 2011 Author Posted October 12, 2011 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.
AdmiralAlkex Posted October 12, 2011 Posted October 12, 2011 @umeaguy Hi neighbour! .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
umeaguy Posted October 14, 2011 Author Posted October 14, 2011 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!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now