using System;
using System.Windows.Forms;
namespace AFKDetector
{
class Program
{
static Timer timer;
static int inactivityThresholdSeconds = 300; // 5 minutes (adjust as needed)
[STAThread]
static void Main()
{
Console.WriteLine("AFK Detector started. Press any key to exit.");
timer = new Timer();
timer.Interval = 1000; // 1 second
timer.Tick += CheckForInactivity;
timer.Start();
// Capture key presses to reset the inactivity timer
Console.ReadKey();
// Cleanup and exit
timer.Stop();
timer.Dispose();
}
static void CheckForInactivity(object sender, EventArgs e)
{
// Check for user inactivity
if (IsUserInactive())
{
Console.WriteLine("User is AFK. Terminating the program.");
Environment.Exit(0);
}
}
static bool IsUserInactive()
{
// Implement your logic to determine user inactivity here
// For simplicity, you can use the System.Windows.Forms.ScreenSaverInUse property
// You may want to use more sophisticated methods to detect user inactivity
return System.Windows.Forms.SystemInformation.ScreenSaverInUse;
}
}
}