Stop keypress from waking monitor

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
niczoom
Posts: 78
Joined: 09 Mar 2016, 22:17

Stop keypress from waking monitor

15 Apr 2016, 01:38

I have a logitech keyboard k400r which has a power button at the top. Using setpoint I have this button setup to run an AHK script which sends a message to my main script to either power my HTPC on or off. Viewing the key history this button does not leave any keycode data, it only detected by the setpoint software.

Now, when my monitor turns off monitor after 'x' minutes when PC is idle (setup in Power options) I would like to only wake the monitor via a press of that power button, I want to disable any 'normal' kepress (a-z, 1-9 etc) and mouse from waking the monitor.

I have tried using 'BlockInput' (with running my script in Admin mode), this blocks the mouse from waking the monitor, but any keypress still wakes the monitor.

Can AHK block all key press's whilst the monitor is off after using SendMessage, 0x112, 0xF170, 2,, Program Manager?
Using a system dll call maybe ?
Attachments
AutoHTPC.ahk
(54.58 KiB) Downloaded 126 times
Last edited by niczoom on 15 Apr 2016, 04:25, edited 1 time in total.
[AHK] 1.1.23.05 x32 Unicode
[WIN] 10 Pro x64 Version 5111 (Build 10586.218)
User avatar
HinkerLoden
Posts: 93
Joined: 23 Mar 2016, 07:50
Contact:

Re: Stop keypress from waking monitor

15 Apr 2016, 02:03

think ahk can only influence software side. the wake up process is hardware/bios controlled. Sometimes you can choose the wake-up keys or input devices in the bios options.
User avatar
niczoom
Posts: 78
Joined: 09 Mar 2016, 22:17

Re: Stop keypress from waking monitor

15 Apr 2016, 04:24

Not waking from sleep/resume.

Blocking the keyboard from waking the monitor after using this command:
SendMessage, 0x112, 0xF170, 2,, Program Manager ;Turn monitor off..
[AHK] 1.1.23.05 x32 Unicode
[WIN] 10 Pro x64 Version 5111 (Build 10586.218)
User avatar
Flarebrass
Posts: 104
Joined: 20 Nov 2015, 13:13
Location: USA
Contact:

Re: Stop keypress from waking monitor

15 Apr 2016, 06:08

If you're not satisfied with Hinker's answer, then we need more information. You mentioned that the computer doesn't go into sleep/hibernate/shutdown mode, so it's actively running but with the monitor powered off. If that's the case, BlockInput, On will prevent your computer from recognizing any keystrokes.

But if that doesn't work, as Hinker said, often those commands are run outside of the OS meaning that AHK would have to detect when the event occurs then send another code to undo said event; it can't flat-out prevent it from happening. Running a loop continuously to check if A_TimePhysicalIdle gets reset will allow you to resend the SendMessage, 0x112, 0xF170, 2,, Program Manager command:

Code: Select all

Loop
{
    if (A_TimePhysicalIde < 1000)
    {
        SendMessage, 0x112, 0xF170, 2,, Program Manager
        Sleep, 2000
    }
    else
        Sleep, 500
}
If you're talking about when the computer is in sleep mode, then I think Device Manager can let you toggle which peripherals can/cannot wake the computer up. I remember reading about a command line function which gave a list of processes and devices which allow the computer to wake up, so a google search can help you in that scenario as well.
(Note that I can't test my code before posting, so beware of bugs! -Flarebrass Amatzikahni)
User avatar
niczoom
Posts: 78
Joined: 09 Mar 2016, 22:17

Re: Stop keypress from waking monitor

15 Apr 2016, 07:08

often those commands are run outside of the OS meaning that AHK would have to detect when the event occurs then send another code to undo said event; it can't flat-out prevent it from happening.
This may be the case.

I'll try to clarify, this has nothing to do with sleep/hibernate/shutdown or mode.

When I send this command : SendMessage, 0x112, 0xF170, 2,, Program Manager, it turns the monitor off.

The only input that I want to turn the monitor back on again is the 'Power Button' on my logitech keyboard (k400r) (apart from Ctrl-Al-Del).

As I mentioned above, this particular button on my keyboard does not act like a normal key, it leaves no keyboard history (ie: Scan Code or Virtual Key code). It can only be programmed within the SetPoint software. I have this button set to run another AHK script which sends a message to turn the monitor back on using SendMessage, 0x112, 0xF170, -1,, Program Manager.

When I tested BlockInput, On (In admin mode), it stopped the mouse input but not the keyboard input.

Possible using AHK?
[AHK] 1.1.23.05 x32 Unicode
[WIN] 10 Pro x64 Version 5111 (Build 10586.218)
User avatar
Flarebrass
Posts: 104
Joined: 20 Nov 2015, 13:13
Location: USA
Contact:

Re: Stop keypress from waking monitor

15 Apr 2016, 09:18

BlockInput should also stop keyboard input. Test a script by doing something like this in Notepad:

Code: Select all

MsgBox,,, Blocking keyboard input., 1000
BlockInput, On
Sleep, 5000
BlockInput, Off
MsgBox,,, Unblocking keyboard input., 1000
Sleep, 5000
MsgBox, Notice any difference?
(Note that I can't test my code before posting, so beware of bugs! -Flarebrass Amatzikahni)
User avatar
niczoom
Posts: 78
Joined: 09 Mar 2016, 22:17

Re: Stop keypress from waking monitor

15 Apr 2016, 16:51

Yes the script works as it should , when run as Admin.

But add this line just after the first MsgBox SendMessage, 0x112, 0xF170, 2,, Program Manager

So now when the monitor is off any keypress turns the monitor back on, if its before the 10 second timeout then the keyboard and mouse are still inactive as they should be.

To note, whilst the monitor is off pressing the power button on the keyboard works as it should, it runs the specified function, but does not turn the monitor on (unless programmed to with SendMessage, 0x112, 0xF170, -1,, Program Manager in the called function).

So look like AHK cannot stop a keypress waking the monitor when turned off using SendMessage, 0x112, 0xF170, 2,, Program Manager.

Could there be a way to suppress the keyboard using a DllCall of some sort ??
[AHK] 1.1.23.05 x32 Unicode
[WIN] 10 Pro x64 Version 5111 (Build 10586.218)
User avatar
Flarebrass
Posts: 104
Joined: 20 Nov 2015, 13:13
Location: USA
Contact:

Re: Stop keypress from waking monitor

18 Apr 2016, 06:45

If BlockInput doesn't work, then either use the first code I posted to quickly resend the message after detecting the event, or you would have to look through the Windows API to find a function usable through DllCall, and I still haven't gotten that far into Windows/AHK yet.
(Note that I can't test my code before posting, so beware of bugs! -Flarebrass Amatzikahni)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750 and 275 guests