模拟睡眠模式(关闭屏幕并禁用输入) [英] Simulated Sleep Mode (turn screen off and disable inputs)

查看:111
本文介绍了模拟睡眠模式(关闭屏幕并禁用输入)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在用c#开发一个程序,该程序要求用户模拟睡眠模式而计算机不会真正进入睡眠状态,并保持程序运行.主要是,我需要关闭屏幕并禁用除电源按钮以外的所有用户输入. 然后,电源按钮将重新启用输入并重新打开屏幕(这将主要用于win8.1平板电脑).这可能吗?

I am developing a program in c# that requires the user to simulate a sleep mode without the computer actually going to sleep and keeps the program running.  Mainly, I need to turn the screen off and disable all user inputs except the power button.  The power button will then re-enable the inputs and turn the screen back on (this will mainly be used on a win8.1 tablet).  Is this possible?

我可以关闭屏幕,但是任何输入都可以重新打开它.

I can turn the screen off, but any input brings it right back on. 

所以我的主要2个问题:如何禁用所有用户输入(键盘/鼠标/触摸屏)?以及如何拦截电源按钮以返回?

So my main 2 questions: How do I disable all user inputs (keyboard/mouse/touchscreen)?  And how do I intercept to the power button to return?

谢谢大家.

PS.如果我要求c/c ++这样做,也可以.

PS.  If I require c/c++ to do this, that's ok too.

推荐答案

您可以使用的发送消息功能 Win32 AP I.在C#中,您可以通过InteropServices调用它.

You can use the send message function of Win32 API. In C#, you may call it via InteropServices.

	using System.Runtime.InteropServices;

        private const int HWND_BROADCAST = 0xFFFF;
        private const int SC_MONITORPOWER = 0xF170;
        private const int WM_SYSCOMMAND = 0x112;

        private const int MONITOR_ON = -1;
        private const int MONITOR_OFF = 2;
        private const int MONITOR_STANBY = 1;

        [DllImport("user32.dll")]
        private static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);


	//turn off monitor
            SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF);


	//turn on monitor
            SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON);


有关WM_SYSCOMMAND的更多详细信息,此处.

More details about WM_SYSCOMMAND here.

要禁用用户输入,可以使用 BlockInput函数.

To disable the user input, you may use the BlockInput function.



这篇关于模拟睡眠模式(关闭屏幕并禁用输入)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆