使用单声道(C#)关闭显示器

时间:2013-04-08 12:07:00

标签: c# linux mono debian

我有以下代码在Windows中关闭显示器,我目前在按钮上单击使用;

[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, int Msg, int wParam, int lParam);
const int SC_MONITORPOWER = 0xF170;
const int WM_SYSCOMMAND = 0x0112;
const int MONITOR_ON = -1;
const int MONITOR_OFF = 2;
const int MONITOR_STANBY = 1;
int onFlag = 0;

private void MonitorOff()
{
    SendMessage(-1, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF);
    onFlag = 1;
}

private void MonitorOn()
{
    if (onFlag == 1)
    {
        SendMessage(-1, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON);
        onFlag = 0;
    }
}

此代码工作正常。我现在想在Linux下做同样的事情(Debian,如果它有所作为)使用mono。显然我无法使用user32.dll所以想知道是否有人知道如何做到这一点?

如果没有实现此功能的内置方法,我想我可以使用these commands ...

1 个答案:

答案 0 :(得分:0)

关于此的一些额外信息;我正在使用树莓派,而xset和setterm命令只会使屏幕空白。为了实际关闭屏幕,我必须使用tvservice -o(关闭)和tvservice -p(开启)。我没有在单声道中找到任何内置方式来执行相同的操作。