I'm trying to make the system, which first records when you click, and then it gives a list of delays between two mouse downs from the record, it is very hard to explain but maybe you will understand when you look at the code. Current code is this:
bool recToggle = false;
public static bool stopbool = false;
public static bool mouseBool = false;
int recDelay = 0;
private void button1_Click(object sender, EventArgs e)
{
if (recToggle)
{
button1.Text = "Start Recording";
//REC IS OFF!
//MessageBox.Show(list.Count.ToString()); //show how many items
//list.ForEach(Console.WriteLine); //print the list
recTimer.Stop();
recToggle = false;
}
else
{
button1.Text = "Stop Recording";
//REC IS ON!
recTimer.Start();
recToggle = true;
}
}
private void recTimer_Tick(object sender, EventArgs e)
{
recTimer.Interval = 1;
if (mouseBool)
{
recDelay = recDelay + 1;
}
if (stopbool)
{
stopbool = false;
list.Add(recDelay);
recDelay = 0;
}
}
public List<int> list = new List<int>();
//hook is working but I didnt put whole code here to make this bit smaller
public static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0 && MouseMessages.WM_LBUTTONDOWN == (MouseMessages)wParam)
{
//mouse down
if (mouseBool)
{
mouseBool = false;
}
else
{
mouseBool = true;
stopbool = true;
}
}
if (nCode >= 0 && MouseMessages.WM_LBUTTONUP == (MouseMessages)wParam)
{
//mouse up
}
return CallNextHookEx(_hookID, nCode, wParam, lParam);
}
It doesn't give any errors, but the delay list numbers are much less than they should be. Timer interval is 1ms, so if you press down, release (1 second) press down again, the value in the list should be 1000, now the values are like 1, 1, 4, 2, and that is almost impossible to click that fast. What is wrong with my code?