The screen saver function must be implemented recently in the development project, that is, when you do not perform any operation on the system within the specified time, the system will automatically enter the screen saver status.
Therefore, a class is encapsulated to obtain mouse and keyboard actions, and a method is provided to return the time when the user does not have an operating system.
The Code is as follows:
Public class mousekeyboardoperate
{
/// <Summary>
/// Create a struct to return the capture time
/// </Summary>
[Structlayout (layoutkind. Sequential)]
Struct lastinputinfo
{
/// <Summary>
/// Set the block capacity of the struct.
/// </Summary>
[Financialas (unmanagedtype. U4)]
Public int cbsize;
/// <Summary>
/// Capture time
/// </Summary>
[Financialas (unmanagedtype. U4)]
Public uint dwtime;
}
[Dllimport ("user32.dll")]
Private Static extern bool getlastinputinfo (ref lastinputinfo plii );
/// <Summary>
/// Obtain the time when no operation is performed on the keyboard or mouse.
/// </Summary>
/// <Returns> the time interval from the last time the user used the system to the present, measured in seconds </returns>
Public static long getlastinputtime ()
{
Lastinputinfo vlastinputinfo = new lastinputinfo ();
Vlastinputinfo. cbsize = marshal. sizeof (vlastinputinfo );
If (! Getlastinputinfo (ref vlastinputinfo ))
{
Return 0;
}
Else
{
Long Count = environment. tickcount-(long) vlastinputinfo. dwtime;
Long icount = count/0/1000;
Return icount;
}
}
}