i am struggling a lot, to capture the key press input in Windows Service
i have KeystrokeAPI which works in console application,
i wrote the below code in OnStart() of the service
protected override void OnStart()
{
using (var api = new KeystrokeAPI())
{
System.Timers.Timer t = new System.Timers.Timer();
t.Elapsed += new ElapsedEventHandler(TimerCallback);
t.Interval = 30000;
t.Enabled = true;
t.AutoReset = true;
api.CreateKeyboardHook((character) => {
// Console.Write(character);
count++;
});
}
}
and Event Handler
protected void TimerCallback(object sender, ElapsedEventArgs e)
{
// Display the date/time when this method got called.
//Console.WriteLine("In TimerCallback: " + DateTime.Now);
//Console.WriteLine("Count Of Keys: " + count);
StreamWriter sw = new StreamWriter(@"d:\ChaiKeyAPILog.txt", true);
sw.WriteLine();
sw.WriteLine("In TimerCallback: " + DateTime.Now);
sw.WriteLine("Count Of Keys: " + count);
sw.Close();
count = 0;
// Force a garbage collection to occur for this demo.
GC.Collect();
}
as i kept timer, so it diplays the datetime for every given interval of time, but it is not displaying the count of the pressed keys of the keyboard.
i tried it in writing this code in Main() also. but no use.
please help me.. to get the count of the pressed keys for every 1 minute of time In windows services