Sign in to follow this  
Followers 0
Xichael

HotKeySet disrupting monitor power off Func, flashing it back on

5 posts in this topic

I'm trying to use a script for powering off my monitor (which works fine on it's own) with a HotKeySet. When I press the assigned hotkey, the monitor does power off, but only for a second, after which it flashes back on. How can I prevent this?

HotKeySet ("#z", "MonOff")

Opt("WinTitleMatchMode", 4)

While 1
    Sleep(50)
WEnd

Func MonOff()
    Local $HWND = WinGetHandle("classname=Progman")
    Local $WM_SYSCommand = 274
    Local $SC_MonitorPower = 61808
    DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND, "int", $WM_SYSCommand, "int", $SC_MonitorPower, "int", 2)
EndFunc

Share this post


Link to post
Share on other sites



I'm trying to use a script for powering off my monitor (which works fine on it's own) with a HotKeySet. When I press the assigned hotkey, the monitor does power off, but only for a second, after which it flashes back on. How can I prevent this?

HotKeySet ("#z", "MonOff")

Opt("WinTitleMatchMode", 4)

While 1
    Sleep(50)
WEnd

Func MonOff()
    Local $HWND = WinGetHandle("classname=Progman")
    Local $WM_SYSCommand = 274
    Local $SC_MonitorPower = 61808
    DllCall("user32.dll", "int", "SendMessage", "hwnd", $HWND, "int", $WM_SYSCommand, "int", $SC_MonitorPower, "int", 2)
EndFunc
I don't really see why you created a new thread for this, as the discussion could've continued on the other thread.

I'm not sure why this script would not work for you though, as it does turn of the monitor(s) and keeps it shut up(if you hold the key down).

To prevent it from turning the screen back on instantly, try with just adding a Sleep(500) in the beginning of the MonOff function, that should let you have enough time to release the keys before the messsage get's sent.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Why not just use this one? It works good for me. The one you posted above doesn't work for me either...

For me the above script does the same thing (same problem as well) with half the code, which helps me more clearly understand how it works... I am on a laptop however, and haven't yet tried it on a desktop.

To prevent it from turning the screen back on instantly, try with just adding a Sleep(500) in the beginning of the MonOff function, that should let you have enough time to release the keys before the messsage get's sent.

That solves it completely. I figured the key releasing after being pressed was waking the screen back up, I just couldn't figure out how to prevent it... Huge thanks.

I don't really see why you created a new thread for this...

My apologies if creating a new thread was excessive. I just figured, new problem, new thread. I'll be easier to reference than were it buried on the last page of an unrelated topic. It's just that whenever I have a problem, I first search the forum for a solution. Hopefully this will be equally useful to someone else someday.

Thanks again guys.

Edited by Xichael

Share this post


Link to post
Share on other sites

Owkidokie :)

Glad you got it to work. Don't give up on getting that evil laptop key to work though. ;)

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