[SOLVED] Turn off the monitor (and block mouse movement) when pressing "Win+Z"
Posted: 24 Nov 2016, 17:35
Hello.
I'm trying to create a script that turns off the monitor when pressing "Win+Z". It also needs to block mouse movement, in order to make sure that the monitor doesn't turn on accidentally when moving the mouse, or if the mouse cursor happens to twitch for a millisecond, or if there's too much light passing through the window and activates the mouse (e.g. the sun coming out of the clouds or something like that). It's an optical mouse.
Here's what I got so far:
The problem is, I run the script, the monitor turns off, but when I move the mouse (or press any mouse button/use the scroll wheel), the monitor turns on again... Except that it shouldn't. And I have no idea why. The mouse movement is still restricted after the monitor turns on and pressing the mouse buttons has no effect until pressing any key. Why isn't the mouse movement blocked during the monitor power off state? Is there a workaround?
I'm trying to create a script that turns off the monitor when pressing "Win+Z". It also needs to block mouse movement, in order to make sure that the monitor doesn't turn on accidentally when moving the mouse, or if the mouse cursor happens to twitch for a millisecond, or if there's too much light passing through the window and activates the mouse (e.g. the sun coming out of the clouds or something like that). It's an optical mouse.
Here's what I got so far:
Code: Select all
#NotrayIcon
#z::
Sleep 700 ; optional, so it doesn't feel too jarring
BlockInput, MouseMove ; turn off the mouse movement and mouse buttons
Hotkey, LButton, nothing, On
Hotkey, MButton, nothing, On
Hotkey, RButton, nothing, On
Hotkey, XButton1, nothing, On
Hotkey, XButton2, nothing, On
Hotkey, WheelUp, nothing, On
Hotkey, WheelDown, nothing, On
Sleep 200 ; required, apparently... At least on Windows 10. It just opens the start menu otherwise (probably due to the Win key from the "Win+Z" key combination)...
SendMessage, 0x112, 0xF170, 2,, Program Manager ; 0x112 is WM_SYSCOMMAND, 0xF170 is SC_MONITORPOWER <-- this is where the magic happens :)
; Press any key to continue...
Input, SingleKey, L1, {LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{Capslock}{Numlock}{PrintScreen}{Pause}
BlockInput, MouseMoveOff ; restore mouse movement and the usage of mouse buttons
Hotkey, LButton, nothing, Off
Hotkey, MButton, nothing, Off
Hotkey, RButton, nothing, Off
Hotkey, XButton1, nothing, Off
Hotkey, XButton2, nothing, Off
Hotkey, WheelUp, nothing, Off
Hotkey, WheelDown, nothing, Off
Nothing:
Return