using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Windows;
using System.Threading;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Collections;
namespace Prova
{
public partial class Form1 : Form
{
#region Dichiarazione Variabili e costanti
int X, Y, pippo;
int ecco = 0;
int acca = 0;
int ripeti = 1;
int ritardo = 2000;
ArrayList x
= new ArrayList
();
ArrayList y
= new ArrayList
();
ArrayList comandi
= new ArrayList
();
ArrayList scriv
= new ArrayList
();
ArrayList press
= new ArrayList
();
[DllImport("user32", CharSet = CharSet.Auto)]
public static extern void mouse_event(int h, int x, int p, int c, int z);
#endregion
#region Simulazione mouse
public int clickdx(int x, int y)
{
Cursor.
Position = new Point
(x, y
);
mouse_event(8, x, y, 0, 0);
mouse_event(16, x, y, 0, 0);
return 1;
}
public int clicksx(int x, int y)
{
Cursor.
Position = new Point
(x, y
);
mouse_event(2, x, y, 0, 0);
mouse_event(4, x, y, 0, 0);
return 1;
}
public int downsx(int x, int y)
{
Cursor.
Position = new Point
(x, y
);
mouse_event(2, x, y, 0, 0);
return 1;
}
public int upsx(int x, int y)
{
Cursor.
Position = new Point
(x, y
);
mouse_event(4, x, y, 0, 0);
return 1;
}
public int downdx(int x, int y)
{
Cursor.
Position = new Point
(x, y
);
mouse_event(8, x, y, 0, 0);
return 1;
}
public int updx(int x, int y)
{
Cursor.
Position = new Point
(x, y
);
mouse_event(16, x, y, 0, 0);
return 1;
}
#endregion
public Form1()
{
InitializeComponent();
}
private void button5_Click(object sender, EventArgs e)
{
// Trova coordinate
progressBar1.Value = 0;
textBox1.Text = "";
textBox2.Text = "";
while (progressBar1.Value < 100)
{
Thread.Sleep(250);
progressBar1.Value += 10;
}
textBox1.Text = Cursor.Position.X.ToString();
textBox2.Text = Cursor.Position.Y.ToString();
progressBar1.Value = 0;
}
private void button2_Click(object sender, EventArgs e)
{
try
{
x.Add(Convert.ToInt32(textBox1.Text));
y.Add(Convert.ToInt32(textBox2.Text));
comandi.Add(1);
textBox6.AppendText("Click Sx (" + textBox1.Text + "," + textBox2.Text + ") ");
}
catch
{
MessageBox.Show("I dati inseriti non sono validi. Riprova");
}
}
private void button3_Click(object sender, EventArgs e)
{
try
{
x.Add(Convert.ToInt32(textBox1.Text));
y.Add(Convert.ToInt32(textBox2.Text));
comandi.Add(2);
textBox6.AppendText("2 click Sx (" + textBox1.Text + "," + textBox2.Text + ") ");
}
catch
{
MessageBox.Show("I dati inseriti non sono validi. Riprova");
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
x.Add(Convert.ToInt32(textBox1.Text));
y.Add(Convert.ToInt32(textBox2.Text));
comandi.Add(3);
textBox6.AppendText("Click dx (" + textBox1.Text + "," + textBox2.Text + ") ");
}
catch
{
MessageBox.Show("I dati inseriti non sono validi. Riprova");
}
}
private void button4_Click(object sender, EventArgs e)
{
try
{
x.Add(Convert.ToInt32(textBox1.Text));
y.Add(Convert.ToInt32(textBox2.Text));
comandi.Add(4);
textBox6.AppendText("Move cursor (" + textBox1.Text + "," + textBox2.Text + ") ");
}
catch
{
MessageBox.Show("I dati inseriti non sono validi. Riprova");
}
}
private void button7_Click(object sender, EventArgs e)
{
x.Clear();
y.Clear();
comandi.Clear();
pippo = 0;
textBox6.Text = "";
ecco = 0;
acca = 0;
}
private void button6_Click(object sender, EventArgs e)
{
int contatore;
int ecco = 0;
this.Enabled = false;
try
{
while (ecco < ripeti)
{
for (contatore = 0; contatore < comandi.Count; contatore++)
{
X = Convert.ToInt32(x[pippo]);
Y = Convert.ToInt32(y[pippo]);
switch (comandi[contatore].ToString())
{
case "1":
clicksx(X, Y);
break;
case "2":
{
clicksx(X, Y);
clicksx(X, Y);
}
break;
case "3":
clickdx(X, Y);
break;
case "4":
Cursor.
Position = new Point
(X, Y
);
break;
case "5":
downsx(X, Y);
break;
case "6":
upsx(X, Y);
break;
case "7":
downdx(X, Y);
break;
case "8":
updx(X, Y);
break;
case "9":
{
SendKeys.SendWait(scriv[ecco].ToString());
ecco++;
}
break;
case "10":
{
SendKeys.SendWait(press[acca].ToString());
acca++;
}
break;
}
Thread.Sleep(ritardo);
pippo++;
}
ecco++;
pippo = 0;
}
ecco = 0;
this.Enabled = true;
}
catch
{
MessageBox.Show("I comandi inseriti non sono validi, riprova");
}
}
private void button8_Click(object sender, EventArgs e)
{
try
{
ritardo = Convert.ToInt32(textBox3.Text);
}
catch
{
MessageBox.Show("I dati inseriti non sono validi. Riprova");
}
}
private void button9_Click(object sender, EventArgs e)
{
try
{
ripeti = Convert.ToInt32(textBox4.Text);
}
catch
{
MessageBox.Show("I dati inseriti non sono validi. Riprova");
}
}
private void button10_Click(object sender, EventArgs e)
{
try
{
x.Add(Convert.ToInt32(textBox1.Text));
y.Add(Convert.ToInt32(textBox2.Text));
comandi.Add(5);
textBox6.AppendText("Down Sx (" + textBox1.Text + "," + textBox2.Text + ") ");
}
catch
{
MessageBox.Show("I dati inseriti non sono validi. Riprova");
}
}
private void button11_Click(object sender, EventArgs e)
{
try
{
x.Add(Convert.ToInt32(textBox1.Text));
y.Add(Convert.ToInt32(textBox2.Text));
comandi.Add(6);
textBox6.AppendText("Up Sx (" + textBox1.Text + "," + textBox2.Text + ") ");
}
catch
{
MessageBox.Show("I dati inseriti non sono validi. Riprova");
}
}
private void button12_Click(object sender, EventArgs e)
{
try
{
x.Add(Convert.ToInt32(textBox1.Text));
y.Add(Convert.ToInt32(textBox2.Text));
comandi.Add(7);
textBox6.AppendText("Down Dx (" + textBox1.Text + "," + textBox2.Text + ") ");
}
catch
{
MessageBox.Show("I dati inseriti non sono validi. Riprova");
}
}
private void button13_Click(object sender, EventArgs e)
{
try
{
x.Add(Convert.ToInt32(textBox1.Text));
y.Add(Convert.ToInt32(textBox2.Text));
comandi.Add(8);
textBox6.AppendText("Up dx (" + textBox1.Text + "," + textBox2.Text + ") ");
}
catch
{
MessageBox.Show("I dati inseriti non sono validi. Riprova");
}
}
private void button14_Click(object sender, EventArgs e)
{
x.Add(Convert.ToInt32(textBox1.Text));
y.Add(Convert.ToInt32(textBox2.Text));
comandi.Add(9);
scriv.Add(textBox5.Text);
textBox6.AppendText("Write(" + textBox5.Text + ") ");
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
button14.Enabled = (textBox5.Text != "");
}
private void button15_Click(object sender, EventArgs e)
{
x.Add(Convert.ToInt32(textBox1.Text));
y.Add(Convert.ToInt32(textBox2.Text));
comandi.Add(10);
press.Add(comboBox1.Text);
textBox6.AppendText("Press " + comboBox1.Text + " ");
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
button15.Enabled = (comboBox1.Text != "");
}
}
}