Detecting that the user is away from the PC with .NET

前端 未结 4 955
借酒劲吻你
借酒劲吻你 2020-12-20 04:10

I have a desktop application in which I would like to know two things:

  1. Is the user currently on the PC (more specifically, is he giving any input to the PC), s
4条回答
  •  梦毁少年i
    2020-12-20 04:25

    Here is the code to detect if a screen saver is running. See this for more details

    const int SPI_GETSCREENSAVERRUNNING = 114;
    
    [DllImport( "user32.dll", CharSet = CharSet.Auto )]
    private static extern bool SystemParametersInfo( 
       int uAction, int uParam, ref bool lpvParam, 
       int flags );
    
    
    // Returns TRUE if the screen saver is actually running
    public static bool GetScreenSaverRunning( )
    {
       bool isRunning = false;
    
       SystemParametersInfo( SPI_GETSCREENSAVERRUNNING, 0, 
          ref isRunning, 0 );
       return isRunning;
    }
    

提交回复
热议问题