本文整理汇总了C#中LASTINPUTINFO类的典型用法代码示例。如果您正苦于以下问题:C# LASTINPUTINFO类的具体用法?C# LASTINPUTINFO怎么用?C# LASTINPUTINFO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LASTINPUTINFO类属于命名空间,在下文中一共展示了LASTINPUTINFO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetLastInputTime
public static DateTime GetLastInputTime()
{
var lastInputInfo = new LASTINPUTINFO();
lastInputInfo.cbSize = (uint)Marshal.SizeOf(lastInputInfo);
GetLastInputInfo(ref lastInputInfo);
return DateTime.Now.AddMilliseconds(-(Environment.TickCount - lastInputInfo.dwTime));
}
示例2: GetLastInputInfo
public static extern bool GetLastInputInfo(ref LASTINPUTINFO lpii);
示例3: getIdleTick
public long getIdleTick()
{
LASTINPUTINFO vLastInputInfo = new LASTINPUTINFO();
vLastInputInfo.cbSize = Marshal.SizeOf(vLastInputInfo);
if (!GetLastInputInfo(ref vLastInputInfo)) return 0;
return Environment.TickCount - (long)vLastInputInfo.dwTime;
}
示例4: Scheduler
/// <summary>
/// This method is responsible for monitoring system resource and user activity with the computer
/// And periodically changes the shared variable 'crawlerState'
/// </summary>
public void Scheduler()
{
PerformanceCounter pc = new PerformanceCounter("Processor", "% Idle Time", "_Total", true);
LASTINPUTINFO info = new LASTINPUTINFO();
info.cbSize = Marshal.SizeOf(typeof(LASTINPUTINFO));
while (GlobalData.RunScheduler)
{
if (GetLastInputInfo(ref info))
{
if ((Environment.TickCount - info.dwTime) / 1000 > 5 && (int)pc.NextValue() > 40)
{
crawlerState = CrawlerState.Run;
}
else
{
crawlerState = CrawlerState.Stop;
if ((Environment.TickCount - info.dwTime) / 1000 <= 5)
GlobalData.lIndexingStatus.Text = string.Format("Indexing is paused and will be resumed in {0} sec of computer inactivity [ CPU Idle : {1:F2}% ]", 5 - (Environment.TickCount - info.dwTime) / 1000, pc.NextValue());
}
}
Thread.Sleep(1000);
}
pc.Close();
}
示例5: GetIdleTick
/// <summary>
/// 取得当前时间与上次输入时间的差
/// </summary>
/// <returns>返回单位 毫秒</returns>
public static long GetIdleTick()
{
LASTINPUTINFO lastInputInfo = new LASTINPUTINFO();
lastInputInfo.cbSize = Marshal.SizeOf(lastInputInfo);
if (!GetLastInputInfo(ref lastInputInfo)) return 0;
return Environment.TickCount - (long)lastInputInfo.dwTime;
}
示例6: CalculateIdleTime
public static TimeSpan CalculateIdleTime() {
if (Environment.OSVersion.Platform == PlatformID.Unix) {
if (haveXprintIdle)
{
var ret = ZkData.Utils.ExecuteConsoleCommand("xprintidle");
if (ret != null) {
int ms;
if (int.TryParse(ret, out ms)) return TimeSpan.FromMilliseconds(ms);
}else{ haveXprintIdle = false;} //some Linux might not have "xprintidle", stop trying, avoid spam in Diagnostic Log.
}
return DateTime.Now - Program.ToolTip.LastUserAction;
}
var systemUptime = Environment.TickCount; // Get the system uptime
var idleTicks = 0; // The number of ticks that passed since last input
var lastInputInfo = new LASTINPUTINFO();
lastInputInfo.cbSize = (uint)Marshal.SizeOf(lastInputInfo);
lastInputInfo.dwTime = 0;
// If we have a value from the function
if (GetLastInputInfo(ref lastInputInfo)) {
var lastInputTicks = (int)lastInputInfo.dwTime; // Get the number of ticks at the point when the last activity was seen
idleTicks = systemUptime - lastInputTicks; // Number of idle ticks = system uptime ticks - number of ticks at last input
}
return TimeSpan.FromMilliseconds(idleTicks);
}
示例7: GetIdleTime
/// <summary>
/// Get the lapse time between user input (mouse or keyboard) system-wide.
/// </summary>
/// <returns>Lapse time in seconds.</returns>
public static double GetIdleTime()
{
LASTINPUTINFO lii = new LASTINPUTINFO();
lii.cbSize = Marshal.SizeOf(lii.GetType());
if (!GetLastInputInfo(ref lii))
throw new ApplicationException("Error executing GetLastInputInfo");
return (Environment.TickCount - lii.dwTime) / 1000.0;
}
示例8: GetIdle
// note MM: http://msdn.microsoft.com/en-us/library/system.environment.tickcount.aspx
// GetLastInputInfo info also goes round this way(although i couldn't find proof on the web)
// but there's a risk of Overflow exception, so i cast them to long to avoid it
// nevertheless, i'm not sure how this code will work after machine working for more than 50 days.
// it depends whether GetLastInputInfo is synchronized with TickCount(behaves same way)
public static uint GetIdle()
{
LASTINPUTINFO structure = new LASTINPUTINFO();
structure.cbSize = Convert.ToUInt32(Marshal.SizeOf(structure));
GetLastInputInfo(ref structure);
// to exclude Overflow exception
return Convert.ToUInt32((long)Environment.TickCount - (long)structure.dwTime);
}
示例9: GetIdleTime
public uint GetIdleTime()
{
LASTINPUTINFO lastInPut = new LASTINPUTINFO();
lastInPut.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(lastInPut);
GetLastInputInfo(ref lastInPut);
return ((uint)Environment.TickCount - lastInPut.dwTime);
}
示例10: Ticks
internal int Ticks()
{
var uptime = Environment.TickCount;
var lastInput = new LASTINPUTINFO();
lastInput.cbSize = Marshal.SizeOf(lastInput);
var idleTicks = 0;
if (GetLastInputInfo(ref lastInput))
idleTicks = uptime - (int)lastInput.dwTime;
return idleTicks;
}
示例11: GetLastInput
public static TimeSpan GetLastInput()
{
var plii = new LASTINPUTINFO();
plii.cbSize = (uint)Marshal.SizeOf(plii);
if (GetLastInputInfo(ref plii))
return TimeSpan.FromMilliseconds(Environment.TickCount - plii.dwTime);
else
throw new Win32Exception(Marshal.GetLastWin32Error());
}
示例12: GetLastInputTime
/// <summary>
/// Gets the last time an input has been received from user
/// </summary>
/// <returns></returns>
private static long GetLastInputTime()
{
LASTINPUTINFO lastInPut = new LASTINPUTINFO();
lastInPut.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(lastInPut);
if (!GetLastInputInfo(ref lastInPut))
{
throw new Exception(GetLastError().ToString());
}
return lastInPut.dwTime;
}
示例13: GetLastInputTime
public static long GetLastInputTime()
{
LASTINPUTINFO lastInPut = new LASTINPUTINFO();
lastInPut.cbSize = (uint)Marshal.SizeOf(lastInPut);
if (!GetLastInputInfo(ref lastInPut))
{
throw new Exception(GetLastError().ToString());
}
return lastInPut.dwTime;
}
示例14: GetIdleTime
public static uint GetIdleTime()
{
LASTINPUTINFO lastInPut = new LASTINPUTINFO();
lastInPut.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(lastInPut);
GetLastInputInfo(ref lastInPut);
//TimeSpan t = TimeSpan.FromMilliseconds(millisecond);
//format(t);
//var s = TimeSpan.FromMilliseconds(lastInPut.dwTime);
//format(s);
return ((uint)Environment.TickCount - lastInPut.dwTime);
// return ((uint)millisecond - lastInPut.dwTime);
}
示例15: GetIdleTime
public static TimeSpan GetIdleTime()
{
TimeSpan idleTime = TimeSpan.FromMilliseconds(0);
LASTINPUTINFO lastInputInfo = new LASTINPUTINFO();
lastInputInfo.cbSize = Marshal.SizeOf(lastInputInfo);
lastInputInfo.dwTime = 0;
if (GetLastInputInfo(ref lastInputInfo))
{
idleTime = TimeSpan.FromMilliseconds(GetTickCount() - (lastInputInfo.dwTime & uint.MaxValue));
}
return idleTime;
}