

(Environment.TickCount - lastInputInfo.dwTime)) LastInputInfo.cbSize = (uint)Marshal.SizeOf(lastInputInfo) In other words, we can get the date and time for the last input like this: var lastInputInfo = new LASTINPUTINFO() After the call the struct we called the method with will have it’s dwTime field set to the tick count when the last input was received by the system. When we call GetLastInputInfo we must call it with a LASTINPUTINFO whose cbSize variable is set to the size of the LASTINPUTINFO struct. Private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii) It will expect a struct called LASTINPUTINFO that we need to create as well. We can call GetLastInputInfo by creating a method with the extern keyword in a C# class. You are welcome to download the source code.įinding out the last time any input was given to the system no matter the source (keyboard, mouse etc) is fairly easy thanks to a function called GetLastInputInfo. As I found this experience rather interesting I’ve put together a little sample application that illustrates how to get the last time of any input to the system as well as the last time for input from the keyboard and the mouse respectively. NET into Windows that I’ve never done before. In order to do so I had to do some low-level hooks from. Mouse Nag detects when you go from using the keyboard to using the mouse no matter what application you are currently running. A couple of weeks ago I built a little Windows application called Mouse Nag with WPF.
