Claro, estás estableciendo la posición del cursor con
SetCursorPos... Sácalo de ahí y veras como funciona.
Te hice un ejemplo en C. Quizás podrías ganar velocidad usando Multihilos.
#include <windows.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
int delay = 100; // Si bajas mucho el rango activar desactivar se confunde.
int active = 0;
printf("Pulsa F1 para iniciar y parar\n");
while (1)
{
Sleep(delay);
if(GetAsyncKeyState(VK_F1))
{
if (active)
{
active = 0;
}else{
active = 1;
}
}
if (active)
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
}
return 0;
}
Espero te sirva de ayuda.