I need to measure time between clicking and how long i hold the mouse button outside the form. For example - i run the app and then click to another window (game, another app or desktop) and i need to get how long this click was.
This is part of my code:
private void button1_MouseDown(object sender, MouseEventArgs e)
{
stopWatch.Stop();
string elapsedTime = stopWatch.ElapsedMilliseconds.ToString();
label2.Text = elapsedTime;
using (StreamWriter sw = new StreamWriter(@"data.txt", true))
{
sw.WriteLine(elapsedTime);
sw.WriteLine(MousePosition.X + "-" + MousePosition.Y);
sw.Flush();
}
stopWatch.Reset();
stopWatch.Start();
}
private void button1_MouseUp(object sender, MouseEventArgs e)
{
stopWatch.Stop();
string elapsedTime = stopWatch.ElapsedMilliseconds.ToString();
label2.Text = elapsedTime;
using (StreamWriter sw = new StreamWriter(@"data.txt", true))
{
sw.WriteLine(elapsedTime);
sw.WriteLine(MousePosition.X + "-" + MousePosition.Y);
sw.Flush();
}
stopWatch.Reset();
stopWatch.Start();
}
But it is just for clicking on the button in the Form. I found and try some codes here and on the internet but none worked.
So please can you help me how to implement this to global mouse click? I will be very grateful for any advice or help.