当前位置: 首页>>代码示例>>C#>>正文


C# LASTINPUTINFO类代码示例

本文整理汇总了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));
 }
开发者ID:substans,项目名称:WindowTracking,代码行数:7,代码来源:InputInformation.cs

示例2: GetLastInputInfo

 public static extern bool GetLastInputInfo(ref LASTINPUTINFO lpii);
开发者ID:pvginkel,项目名称:SystemEx,代码行数:1,代码来源:NativeMethods.Methods.cs

示例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;
 }
开发者ID:yadewe,项目名称:YDW,代码行数:7,代码来源:UserOpration.cs

示例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();
        }
开发者ID:vineelkovvuri,项目名称:ExtendableDesktopSearch,代码行数:29,代码来源:FileSystemCrawler.cs

示例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;
 } 
开发者ID:peisheng,项目名称:EASYFRAMEWORK,代码行数:11,代码来源:WindowsUtil.cs

示例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);
        }
开发者ID:GoogleFrog,项目名称:Zero-K-Infrastructure,代码行数:28,代码来源:WindowsApi.cs

示例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;
 }
开发者ID:krbysn,项目名称:jabber-net,代码行数:12,代码来源:IdleTime.cs

示例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);
 }
开发者ID:MarkiyanMatsekh,项目名称:WorkHelp,代码行数:13,代码来源:Win32Wrapper.cs

示例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);
        }
开发者ID:burnssun,项目名称:BzAB,代码行数:8,代码来源:AutoBackupModel.cs

示例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;
 }
开发者ID:jb3622,项目名称:Jalapeno,代码行数:10,代码来源:IdleTime.cs

示例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());
        }
开发者ID:ssnake,项目名称:utuner,代码行数:10,代码来源:win32.cs

示例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;
        }
开发者ID:mohanaravind,项目名称:ProjectSeniorCenter,代码行数:15,代码来源:Win32.cs

示例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;
        }
开发者ID:triffids,项目名称:Hibernator,代码行数:12,代码来源:EnvironmentInfo.cs

示例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);
        }
开发者ID:triffids,项目名称:Hibernator,代码行数:14,代码来源:EnvironmentInfo.cs

示例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;
        }
开发者ID:modenl,项目名称:CoStart,代码行数:15,代码来源:IdleDetector.cs


注:本文中的LASTINPUTINFO类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。