
10/11/2011, 14:25
|
 | | | Fecha de Ingreso: septiembre-2009
Mensajes: 82
Antigüedad: 15 años, 4 meses Puntos: 2 | |
Respuesta: Simple Click Ya habia tenido un prblema asi, aqui te dejo la clase para dar auto clic y que solito el mouse de clic derecho o izquierdo en la posicion donde tu le indiques el intervalo de tiempo en que quieres que de clic el mouse
public class AutoClic
{
const int MOUSEEVENTF_LEFTDOWN = 2;
const int MOUSEEVENTF_LEFTUP = 4;
const int MOUSEEVENTF_RIGHTDOWN = 8;
const int MOUSEEVENTF_RIGHT_UP = 16;
const int INPUT_MOUSE = 0;
[DllImport("User32.dll", SetLastError = true)]
public static extern int SendInput(int nInputs, ref INPUT pInputs, int cbSize);
private Point ClicLocation = new Point();
private Timer tmrLapso = null;
private bool ClicDerecho = false;
private bool ClicIzquierdo = false;
public AutoClic()
{
InicializarComponentes();
}
private void InicializarComponentes()
{
tmrLapso = new Timer();
tmrLapso.Enabled = false;
tmrLapso.Tick += new EventHandler(tmrLapso_Tick);
}
void tmrLapso_Tick(object sender, EventArgs e)
{
Cursor.Position = ClicLocation;
INPUT i = new INPUT();
i.type = INPUT_MOUSE;
i.mi.dx = 0; //ClicLocation.X;
i.mi.dy = 0; // ClicLocation.Y;
i.mi.mouseData = 0;
i.mi.time = 0;
if (ClicIzquierdo)
{
i.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
SendInput(1, ref i, Marshal.SizeOf(i));
i.mi.dwExtraInfo = IntPtr.Zero;
i.mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(1, ref i, Marshal.SizeOf(i));
}
if (ClicDerecho)
{
i.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
SendInput(1, ref i, Marshal.SizeOf(i));
i.mi.dwExtraInfo = IntPtr.Zero;
i.mi.dwFlags = MOUSEEVENTF_RIGHT_UP;
SendInput(1, ref i, Marshal.SizeOf(i));
}
}
public void DarClicDerecho(Point Localizacion, int Segundos)
{
ClicDerecho = true;
ClicIzquierdo = false;
ClicLocation = Localizacion;
Segundos = Segundos * 1000;
tmrLapso.Interval = Segundos;
tmrLapso.Start();
}
public void DarClicIzquierdo(Point Localizacion, int Segundos)
{
ClicIzquierdo = true;
ClicDerecho = false;
ClicLocation = Localizacion;
Segundos = Segundos * 1000;
tmrLapso.Interval = Segundos;
tmrLapso.Start();
}
public void DetenerAutoClic()
{
ClicDerecho = false;
ClicIzquierdo = false;
tmrLapso.Stop();
}
#region ESTRUCTURAS
public struct MOUSEINPUT
{
public int dx;
public int dy;
public int mouseData;
public int dwFlags;
public int time;
public IntPtr dwExtraInfo;
}
public struct INPUT
{
public uint type;
public MOUSEINPUT mi;
};
#endregion
}
Para hacer uso de esta clase, tienes que crear una nueva instancia de esta, y mandar a llamar a sus metodos.
Ejemplo:
Point Posicion=new Point (200,500);
AutoClic objClic=new AutoClic();
objClic.DarClicIzquierdo(Posicion,10);
Al mandar a llamar el metodo, solito el mouse empieza a dar clic izquierdo en la Posicion 200,500 cada 10 segundos.
Sale espero le saques provecho a la clase
Última edición por JxDarkAngel; 10/11/2011 a las 14:25
Razón: ortografia
|