So now I have this: hooked hotkeys and a volatile bool
that is checking in a while loop.
UserActivityHook actHook;
private void Form1_Load(object sender, EventArgs e)
{
actHook = new UserActivityHook();
actHook.KeyPress += new KeyPressEventHandler(klawisze);
actHook.KeyDown += new KeyEventHandler(klawisze2);
actHook.Start();
}
public void pw()
{
while (!stopIt)
{
SetCursorPos(576, 363);
Thread.Sleep(50);
SetCursorPos(650, 363);
Thread.Sleep(50);
SetCursorPos(650, 430);
Thread.Sleep(50);
}
}
public void Stop()
{
stopIt = true;
}
private volatile bool stopIt;
public void dw()
{
while (!stopIt)
{
SetCursorPos(860, 350);
Thread.Sleep(50);
SetCursorPos(890, 350);
Thread.Sleep(50);
SetCursorPos(890, 380);
Thread.Sleep(50);
}
}
public void klawisze(object sender, KeyPressEventArgs e)
{
Thread w1 = new Thread(new ThreadStart(pw));
Thread w2 = new Thread(new ThreadStart(dw));
try
{
if (e.KeyChar == 21) //CTRL + SHIFT + U
{ //1
stopIt = false;
w1.Start();
if (e.KeyChar == 9)
{
Stop();
w1.Join();
}
}
if (e.KeyChar == 9) //CTRL + SHIFT + I
{ //2
stopIt = false;
w2.Start();
if (e.KeyChar == 21)
{
Stop();
w2.Join();
}
}
}
It's not closing first drawing and in effect when i press 1st hotkey and then second its drawing 2 triangles at same time. What is wrong here?