home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
General Forums
Newcomers Forum
PowerScheduler client and mouse inactivity
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="dero" data-source="post: 236251" data-attributes="member: 29291"><p>Hm, that's strange. Somehow the mouse/keyboard detection does not work...</p><p></p><p>Anyone of you able to do test this C#-sniplet on his system? (The result of GetLastInputTime)</p><p></p><p>[CODE] /// <summary></p><p> /// struct for GetLastInpoutInfo</p><p> /// </summary></p><p> internal struct LASTINPUTINFO</p><p> {</p><p> public uint cbSize;</p><p> public uint dwTime;</p><p> }</p><p></p><p> /// <summary></p><p> /// The GetLastInputInfo function retrieves the time of the last input event.</p><p> /// </summary></p><p> /// <param name="plii"></param></p><p> /// <returns></returns></p><p> [DllImport("user32.dll")]</p><p> static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);</p><p></p><p> /// <summary></p><p> /// Returns the current tick as uint (pref. over Environemt.TickCount which only uses int)</p><p> /// </summary></p><p> /// <returns></returns></p><p> [DllImport("kernel32.dll")]</p><p> static extern uint GetTickCount();</p><p></p><p> /// <summary></p><p> /// This functions returns the time of the last user input recogniized,</p><p> /// i.e. mouse moves or keyboard inputs.</p><p> /// </summary></p><p> /// <returns>Last time of user input</returns></p><p> DateTime GetLastInputTime()</p><p> {</p><p> LASTINPUTINFO lastInputInfo = new LASTINPUTINFO();</p><p> lastInputInfo.cbSize = (uint) Marshal.SizeOf(lastInputInfo);</p><p></p><p> if (!GetLastInputInfo(ref lastInputInfo))</p><p> {</p><p> return DateTime.MinValue;</p><p> }</p><p></p><p> long lastKick= lastInputInfo.dwTime;</p><p> long tick = GetTickCount();</p><p></p><p> long delta = lastKick - tick;</p><p></p><p> if (delta > 0)</p><p> {</p><p> </p><p> // there was an overflow (restart at 0) in the tick-counter!</p><p> delta = delta - uint.MaxValue - 1;</p><p> }</p><p></p><p> return DateTime.Now.AddMilliseconds( delta );</p><p> }</p><p>[/CODE]</p><p></p><p>Regards</p><p></p><p>dero</p></blockquote><p></p>
[QUOTE="dero, post: 236251, member: 29291"] Hm, that's strange. Somehow the mouse/keyboard detection does not work... Anyone of you able to do test this C#-sniplet on his system? (The result of GetLastInputTime) [CODE] /// <summary> /// struct for GetLastInpoutInfo /// </summary> internal struct LASTINPUTINFO { public uint cbSize; public uint dwTime; } /// <summary> /// The GetLastInputInfo function retrieves the time of the last input event. /// </summary> /// <param name="plii"></param> /// <returns></returns> [DllImport("user32.dll")] static extern bool GetLastInputInfo(ref LASTINPUTINFO plii); /// <summary> /// Returns the current tick as uint (pref. over Environemt.TickCount which only uses int) /// </summary> /// <returns></returns> [DllImport("kernel32.dll")] static extern uint GetTickCount(); /// <summary> /// This functions returns the time of the last user input recogniized, /// i.e. mouse moves or keyboard inputs. /// </summary> /// <returns>Last time of user input</returns> DateTime GetLastInputTime() { LASTINPUTINFO lastInputInfo = new LASTINPUTINFO(); lastInputInfo.cbSize = (uint) Marshal.SizeOf(lastInputInfo); if (!GetLastInputInfo(ref lastInputInfo)) { return DateTime.MinValue; } long lastKick= lastInputInfo.dwTime; long tick = GetTickCount(); long delta = lastKick - tick; if (delta > 0) { // there was an overflow (restart at 0) in the tick-counter! delta = delta - uint.MaxValue - 1; } return DateTime.Now.AddMilliseconds( delta ); } [/CODE] Regards dero [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
General Forums
Newcomers Forum
PowerScheduler client and mouse inactivity
Contact us
RSS
Top
Bottom