I need to create a program that monitors a computer for activity. Such as a mouse move, mouse click or keyboard input. I don't need to record what has happened just that the computer is in use. If their computer has not been in use for a certain period of time, i.e. 15 mins, I need to fire off an event.
Is there a way that I can get notified of these events?
The Activity Recognition API automatically detects activities by periodically reading short bursts of sensor data and processing them using machine learning models.
It means that a human should place wearable sensors on their body for the system to collect data. The second approach is vision-based, i.e. human activity recognition from video or images. In this case, the system gathers data with a camera to identify activities.
Device sensors provide insights into what persons are doing in real-time (walking, running, driving, etc.). Knowing users' activity allows, for instance, to interact with them through an app.
Thank you LordCover. This code is from here. This class takes control of the keyboard and mouse controls for you. You can use in a timer like this:
private void timer1_Tick(object sender, EventArgs e)
{
listBox1.Items.Add(Win32.GetIdleTime().ToString());
if (Win32.GetIdleTime() > 60000) // 1 minute
{
textBox1.Text = "SLEEPING NOW";
}
}
Main code for control. Paste to your form code.
internal struct LASTINPUTINFO
{
public uint cbSize;
public uint dwTime;
}
public class Win32
{
[DllImport("User32.dll")]
public static extern bool LockWorkStation();
[DllImport("User32.dll")]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
[DllImport("Kernel32.dll")]
private static extern uint GetLastError();
public static uint GetIdleTime()
{
LASTINPUTINFO lastInPut = new LASTINPUTINFO();
lastInPut.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(lastInPut);
GetLastInputInfo(ref lastInPut);
return ((uint)Environment.TickCount - lastInPut.dwTime);
}
public 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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With