themax90 Posted September 4, 2005 Share Posted September 4, 2005 (edited) Heres a monitor script, really self explanitory, press f12, turns off monitor, press f11, turns it on, esc exits the program... MsgBox(0, "Started", @ScriptName & " has started.... F12 = Monitor off, F11 = Monitor on, Esc = Exit Program.") Opt("WinTitleMatchMode", 4) While 1 If _IsPressed(0x1B) Then $hwnd = WinGetHandle('classname=Progman') DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hwnd, 'int', 274, 'int', 61808, 'int', -1) MsgBox(0, "Closing...", "Closing program.....") Exit ElseIf _IsPressed(0x7A) Then $hwnd = WinGetHandle('classname=Progman') DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hwnd, 'int', 274, 'int', 61808, 'int', -1) ElseIf _IsPressed(0x7B) Then $hwnd = WinGetHandle('classname=Progman') Sleep(500) DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hwnd, 'int', 274, 'int', 61808, 'int', 2) EndIf WEnd Func _IsPressed($hexKey) Global $aR, $bRv $dll = DllOpen("user32.dll") $aR = DllCall($dll, "int", "GetAsyncKeyState", "int", $hexKey) DllClose($dll) If $aR[0] <> 0 Then $bRv = 1 Else $bRv = 0 EndIf Return $bRv EndFunc ;==>_IsPressed Edit: made it alittle bit more idiot proof by telling u it's on... Edited September 4, 2005 by AutoIt Smith Link to comment Share on other sites More sharing options...
LxP Posted September 4, 2005 Share Posted September 4, 2005 Nice work! One small problem however: 100% CPU.You could get around that by using HotkeySet() instead of continually polling _IsPressed() but that would then disallow the use of F12 as a hotkey.I have other programs on my system that can be configured to use F12 as a hotkey. I wonder why AutoIt doesn't allow it? Perhaps the only way to achieve this is to use a hook... Link to comment Share on other sites More sharing options...
layer Posted September 4, 2005 Share Posted September 4, 2005 @LxP, You just saved me haha. I was re-writing his script with hotkeys... Then I refreshed the page, and I saw you posted and said F12 can't be used... FootbaG Link to comment Share on other sites More sharing options...
themax90 Posted September 4, 2005 Author Share Posted September 4, 2005 (edited) QuickFix.... F11 = Off F10 = On Esc = Close Edit..... Uses 2% cpu usage now MsgBox(0, "Started", @ScriptName & " has started.... F11 = Monitor off, F10 = Monitor on, Esc = Exit Program.") Opt ("WinTitleMatchMode", 4) HotKeySet("{F11}", "MonOff") HotKeySet("{F10}", "MonOn") HotKeySet("{Esc}", "Close") While 1 Sleep(10) WEnd Func Close() $hwnd = WinGetHandle('classname=Progman') DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hwnd, 'int', 274, 'int', 61808, 'int', -1) MsgBox(0, "Closing...", "Closing program.....") Exit EndFunc;==>Close Func MonOn() $hwnd = WinGetHandle('classname=Progman') DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hwnd, 'int', 274, 'int', 61808, 'int', -1) EndFunc;==>MonOn Func MonOff() $hwnd = WinGetHandle('classname=Progman') Sleep(500) DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hwnd, 'int', 274, 'int', 61808, 'int', 2) EndFunc;==>MonOff [Edit] It seems the Continous While statement overclocks the processor by just restringing the entire program since nothing happens. If it sleeps 10 milliseconds, then the program halts, saving memory and usage, but still providing a fast surface for pressing a key. It will still catch the key even in a very short sleep. If it is raised it might turn the cpu usage to 0 or 1......[/Edit] [Edit2] If you change the Sleep to 30 miliseconds it stays at 0% most of the time but when rapid mouse movement occurs it raises to 1%, Sleep(30) works and responds the same as what LxP has posted below.[/Edit2] Edited September 4, 2005 by AutoIt Smith Link to comment Share on other sites More sharing options...
LxP Posted September 4, 2005 Share Posted September 4, 2005 If you change this: while 1 sleep(10) wEnd to this: while 1 sleep(0x7fffffff) wEnd then you may find that CPU usage drops down to 0%! Link to comment Share on other sites More sharing options...
themax90 Posted September 4, 2005 Author Share Posted September 4, 2005 (edited) To still use F12 and F11 you can use this. This implements a Memory reduction method I pulled from the Online Radio thread, and a few sleeps that dont interfere with the key pressing. Only uses about 9 - 11 % expandcollapse popupAdlibEnable("Mem") MsgBox(0, "Started", @ScriptName & " has started.... F12 = Monitor off, F11 = Monitor on, Esc = Exit Program.") Opt ("WinTitleMatchMode", 4) While 1 Sleep(10) If _IsPressed(0x1B) Then $hwnd = WinGetHandle('classname=Progman') DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hwnd, 'int', 274, 'int', 61808, 'int', -1) MsgBox(0, "Closing...", "Closing program.....") Exit ElseIf _IsPressed(0x7A) Then $hwnd = WinGetHandle('classname=Progman') DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hwnd, 'int', 274, 'int', 61808, 'int', -1) Sleep(10) ElseIf _IsPressed(0x7B) Then $hwnd = WinGetHandle('classname=Progman') Sleep(500) DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hwnd, 'int', 274, 'int', 61808, 'int', 2) Sleep(10) EndIf Sleep(20) WEnd Func _IsPressed($hexKey) Global $aR, $bRv $dll = DllOpen("user32.dll") $aR = DllCall($dll, "int", "GetAsyncKeyState", "int", $hexKey) DllClose($dll) If $aR[0] <> 0 Then $bRv = 1 Else $bRv = 0 EndIf Return $bRv EndFunc;==>_IsPressed Func Mem() Local $aHandle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1F0FFF, 'int', False, 'int', -1), $aReturn = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $aHandle[0]) DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $aHandle[0]) Return $aReturn[0] EndFunc;==>Mem [Edit] I made this for my girlfriend who's mom doesn't know she has an internet connection in her room, so when she gets on, she can use this program to hide the monitor if her mom ever comes into her room. I think it would be to confusing the give her the first fix using F11 and F10, so I will just give her this version that doesn't switch anything, she won't even know about that memory hole in the first version I gave her.[/Edit] Edited September 4, 2005 by AutoIt Smith Link to comment Share on other sites More sharing options...
theguy0000 Posted September 5, 2005 Share Posted September 5, 2005 (edited) wait...i dont understand what this does *idiot* lol edit: oh i get it...ithought something was wrong with my comp when i presses F12 maybe change F11 to something else though, F12 messes with the window Edited September 5, 2005 by theguy0000 The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
ConsultingJoe Posted July 26, 2006 Share Posted July 26, 2006 hey guys, I have a question about this. I have used it before on my desktop but on my laptop that is running xp sp2 pro the lcd shuts off for one second and comes back on, is there a reason for this? Thanks [center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center] Link to comment Share on other sites More sharing options...
themax90 Posted July 26, 2006 Author Share Posted July 26, 2006 Wow. Bumped from 1 year ago. Um... No idea.... I forgot I authored this one.... Link to comment Share on other sites More sharing options...
ConsultingJoe Posted July 26, 2006 Share Posted July 26, 2006 Wow. Bumped from 1 year ago. Um... No idea.... I forgot I authored this one....ok, then thanks [center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center] Link to comment Share on other sites More sharing options...
james3mg Posted July 26, 2006 Share Posted July 26, 2006 (edited) I've been looking for this method of shutting off a monitor! Don't know why I couldn't find anything in the search. Anyway, I used AutoItSmith's script as a base for this one that shuts off the monitor at 10:00 PM (or whatever time you want - change it in the script) and turns it back on at 6:00 AM. The nice thing is that it doesn't lock it into the "off" mode - if you need it, wiggle the mouse or press Esc and it'll turn back on. It will then stay on for 5 minutes past the last mouse movement, then turn back off until 6:00 AM the next morning. I wrote this for my home PC - I like the screensaver, but the monitor is too bright at night (and I'd like something automatic rather than having to turn off the monitor each night - my current solution).expandcollapse popupOpt("WinTitleMatchMode", 4) While 1 Sleep(100) If @Hour >= 15 OR @Hour < 6 Then Do $MousePos = MouseGetPos() $hwnd = WinGetHandle('classname=Progman') Sleep(500) DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hwnd, 'int', 274, 'int', 61808, 'int', 2) If _IsPressed(0x1B) OR Abs($MousePos[0]-MouseGetPos(0)) > 5 OR Abs($MousePos[1]-MouseGetPos(1)) > 5 Then $hwnd = WinGetHandle('classname=Progman') DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hwnd, 'int', 274, 'int', 61808, 'int', -1) $MousePos = MouseGetPos() $MouseTimer = TimerInit() Do Sleep(500) If Abs($MousePos[0]-MouseGetPos(0)) > 5 OR Abs($MousePos[1]-MouseGetPos(1)) > 5 Then $MouseTimer = TimerInit() $MousePos = MouseGetPos() EndIf Until TimerDiff($MouseTimer) > 300000 ExitLoop EndIf Until @Hour = 6 EndIf WEnd Func _IsPressed($hexKey) Global $aR, $bRv $dll = DllOpen("user32.dll") $aR = DllCall($dll, "int", "GetAsyncKeyState", "int", $hexKey) DllClose($dll) If $aR[0] <> 0 Then $bRv = 1 Else $bRv = 0 EndIf Return $bRv EndFunc ;==>_IsPressed Edited July 26, 2006 by james3mg "There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110 Link to comment Share on other sites More sharing options...
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