Block systemwide mouse input

Hi everyone,

I’m writing an application that allows the user to put the display to sleep with a keystroke combination.

The issue I’m running into is that Windows wakes up the screen almost immediately with the tiniest movement of the mouse. For example, I’ll put my screen to sleep, then as I stand up from my desk, the tiny shaking of my chair moves the mouse a pixel, and the screen immediately wakes up. Or a truck will drive by my house and the vibration is enough to move the mouse and wake up the screen.

This does not happen on my laptop where the pointing device is a trackpad. This also does not happen on Mac as when the screen is asleep Mac disables mouse movement, and must be woken up with either a mouse click or a keyboard keypress.

I would like to replicate the Mac behavior on Windows and disable mouse movement once the screen is asleep.

I’ve looked at the BlockInput API, but that blocks both mouse and keyboard input and leaves the user with no way to wake up the screen.

Does anyone know a good approach to this?

Thanks in advance.

at windows at device manager right mouse at “your” pointer device contextmenu settings
you should see a tab energy management
then a checkbox if this device can awake the pc.

at windows you add a keystroke combination to a link to execute it.

changing system settings or behavior with a app is not ok.

I’d be surprised if that works for the screensaver as the computer isn’t asleep when the screensaver is on, that setting is for low level resume from sleep.

The screensaver is just an app so I’d try this:

  1. Watch for the execution of scrnsave.scr or hook it when you do your key combo (so you aren’t hooked all the time)
  2. Hook WH_MOUSE_LL with SetWindowsHookEx
  3. In the LowLevelMouseProc, listen for 0x200 (512) WM_MOUSEMOVE and return 1 if scrnsave.scr is active else call CallNextHookEx

I’m on my wednesday out and about with my laptop, let me know if you get stuck and I’ll take a look when I get back to my pc later.