Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Emulator 1.1 - Form1.cs

Form1.cs

Caricato da: Matthew
Scarica il programma completo

  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Diagnostics;
  10. using System.Windows;
  11. using System.Threading;
  12. using Microsoft.Win32;
  13. using System.Runtime.InteropServices;
  14. using System.Collections;
  15.  
  16. namespace Prova
  17. {
  18.     public partial class Form1 : Form
  19.     {
  20.         #region Dichiarazione Variabili e costanti
  21.  
  22.         int X, Y, pippo;
  23.         int ecco = 0;
  24.         int acca = 0;
  25.         int ripeti = 1;
  26.         int ritardo = 2000;
  27.         ArrayList x = new ArrayList();
  28.         ArrayList y = new ArrayList();
  29.         ArrayList comandi = new ArrayList();
  30.         ArrayList scriv = new ArrayList();
  31.         ArrayList press = new ArrayList();
  32.  
  33.         [DllImport("user32", CharSet = CharSet.Auto)]
  34.         public static extern void mouse_event(int h, int x, int p, int c, int z);
  35.  
  36.         #endregion
  37.  
  38.         #region Simulazione mouse
  39.         public int clickdx(int x, int y)
  40.         {
  41.             Cursor.Position = new Point(x, y);
  42.             mouse_event(8, x, y, 0, 0);
  43.             mouse_event(16, x, y, 0, 0);
  44.             return 1;
  45.         }
  46.  
  47.         public int clicksx(int x, int y)
  48.         {
  49.             Cursor.Position = new Point(x, y);
  50.             mouse_event(2, x, y, 0, 0);
  51.             mouse_event(4, x, y, 0, 0);
  52.             return 1;
  53.         }
  54.  
  55.         public int downsx(int x, int y)
  56.         {
  57.             Cursor.Position = new Point(x, y);
  58.             mouse_event(2, x, y, 0, 0);
  59.             return 1;
  60.         }
  61.  
  62.         public int upsx(int x, int y)
  63.         {
  64.             Cursor.Position = new Point(x, y);
  65.             mouse_event(4, x, y, 0, 0);
  66.             return 1;
  67.         }
  68.  
  69.         public int downdx(int x, int y)
  70.         {
  71.             Cursor.Position = new Point(x, y);
  72.             mouse_event(8, x, y, 0, 0);
  73.             return 1;
  74.         }
  75.  
  76.         public int updx(int x, int y)
  77.         {
  78.             Cursor.Position = new Point(x, y);
  79.             mouse_event(16, x, y, 0, 0);
  80.             return 1;
  81.         }
  82.  
  83.         #endregion
  84.  
  85.         public Form1()
  86.         {
  87.             InitializeComponent();
  88.            
  89.         }
  90.  
  91.         private void button5_Click(object sender, EventArgs e)
  92.         {
  93.             // Trova coordinate
  94.  
  95.             progressBar1.Value = 0;
  96.             textBox1.Text = "";
  97.             textBox2.Text = "";
  98.             while (progressBar1.Value < 100)
  99.             {
  100.                 Thread.Sleep(250);
  101.                 progressBar1.Value += 10;
  102.             }
  103.             textBox1.Text = Cursor.Position.X.ToString();
  104.             textBox2.Text = Cursor.Position.Y.ToString();
  105.             progressBar1.Value = 0;
  106.         }
  107.  
  108.         private void button2_Click(object sender, EventArgs e)
  109.         {
  110.             try
  111.             {
  112.                 x.Add(Convert.ToInt32(textBox1.Text));
  113.                 y.Add(Convert.ToInt32(textBox2.Text));
  114.                 comandi.Add(1);
  115.                 textBox6.AppendText("Click Sx (" + textBox1.Text + "," + textBox2.Text + ")   ");
  116.             }
  117.             catch
  118.             {
  119.                 MessageBox.Show("I dati inseriti non sono validi. Riprova");
  120.             }
  121.         }
  122.  
  123.         private void button3_Click(object sender, EventArgs e)
  124.         {
  125.             try
  126.             {
  127.                 x.Add(Convert.ToInt32(textBox1.Text));
  128.                 y.Add(Convert.ToInt32(textBox2.Text));
  129.                 comandi.Add(2);
  130.  
  131.                 textBox6.AppendText("2 click Sx (" + textBox1.Text + "," + textBox2.Text + ")   ");
  132.             }
  133.             catch
  134.             {
  135.                 MessageBox.Show("I dati inseriti non sono validi. Riprova");
  136.             }
  137.         }
  138.  
  139.         private void button1_Click(object sender, EventArgs e)
  140.         {
  141.             try
  142.             {
  143.                 x.Add(Convert.ToInt32(textBox1.Text));
  144.                 y.Add(Convert.ToInt32(textBox2.Text));
  145.                 comandi.Add(3);
  146.  
  147.                 textBox6.AppendText("Click dx (" + textBox1.Text + "," + textBox2.Text + ")   ");
  148.             }
  149.             catch
  150.             {
  151.                 MessageBox.Show("I dati inseriti non sono validi. Riprova");
  152.             }
  153.         }
  154.  
  155.         private void button4_Click(object sender, EventArgs e)
  156.         {
  157.             try
  158.             {
  159.                 x.Add(Convert.ToInt32(textBox1.Text));
  160.                 y.Add(Convert.ToInt32(textBox2.Text));
  161.                 comandi.Add(4);
  162.  
  163.                 textBox6.AppendText("Move cursor (" + textBox1.Text + "," + textBox2.Text + ")   ");
  164.             }
  165.             catch
  166.             {
  167.                 MessageBox.Show("I dati inseriti non sono validi. Riprova");
  168.             }
  169.         }
  170.  
  171.         private void button7_Click(object sender, EventArgs e)
  172.         {
  173.             x.Clear();
  174.             y.Clear();
  175.             comandi.Clear();
  176.             pippo = 0;
  177.             textBox6.Text = "";
  178.             ecco = 0;
  179.             acca = 0;
  180.  
  181.         }
  182.  
  183.         private void button6_Click(object sender, EventArgs e)
  184.         {
  185.             int contatore;
  186.             int ecco = 0;
  187.             this.Enabled = false;
  188.  
  189.             try
  190.             {
  191.                 while (ecco < ripeti)
  192.                 {
  193.  
  194.                     for (contatore = 0; contatore < comandi.Count; contatore++)
  195.                     {
  196.                         X = Convert.ToInt32(x[pippo]);
  197.                         Y = Convert.ToInt32(y[pippo]);
  198.  
  199.                         switch (comandi[contatore].ToString())
  200.                         {
  201.                             case "1":
  202.                                 clicksx(X, Y);
  203.                                 break;
  204.                             case "2":
  205.                                 {
  206.                                     clicksx(X, Y);
  207.                                     clicksx(X, Y);
  208.                                 }
  209.                                 break;
  210.                             case "3":
  211.                                 clickdx(X, Y);
  212.                                 break;
  213.                             case "4":
  214.                                 Cursor.Position = new Point(X, Y);
  215.                                 break;
  216.                             case "5":
  217.                                 downsx(X, Y);
  218.                                 break;
  219.                             case "6":
  220.                                 upsx(X, Y);
  221.                                 break;
  222.                             case "7":
  223.                                 downdx(X, Y);
  224.                                 break;
  225.                             case "8":
  226.                                 updx(X, Y);
  227.                                 break;
  228.                             case "9":
  229.                                 {
  230.                                     SendKeys.SendWait(scriv[ecco].ToString());
  231.                                     ecco++;
  232.                                 }
  233.                                 break;
  234.                             case "10":
  235.                                 {
  236.                                     SendKeys.SendWait(press[acca].ToString());
  237.                                     acca++;
  238.                                 }
  239.                                 break;
  240.                         }
  241.                         Thread.Sleep(ritardo);
  242.                         pippo++;
  243.                     }
  244.                     ecco++;
  245.                     pippo = 0;
  246.                 }
  247.                 ecco = 0;
  248.                 this.Enabled = true;
  249.             }
  250.  
  251.             catch
  252.             {
  253.                 MessageBox.Show("I comandi inseriti non sono validi, riprova");
  254.             }
  255.         }
  256.  
  257.         private void button8_Click(object sender, EventArgs e)
  258.         {
  259.             try
  260.             {
  261.                 ritardo = Convert.ToInt32(textBox3.Text);
  262.             }
  263.             catch
  264.             {
  265.                 MessageBox.Show("I dati inseriti non sono validi. Riprova");
  266.             }
  267.  
  268.         }
  269.  
  270.         private void button9_Click(object sender, EventArgs e)
  271.         {
  272.             try
  273.             {
  274.                 ripeti = Convert.ToInt32(textBox4.Text);
  275.             }
  276.             catch
  277.             {
  278.                 MessageBox.Show("I dati inseriti non sono validi. Riprova");
  279.             }
  280.         }
  281.  
  282.         private void button10_Click(object sender, EventArgs e)
  283.         {
  284.             try
  285.             {
  286.                 x.Add(Convert.ToInt32(textBox1.Text));
  287.                 y.Add(Convert.ToInt32(textBox2.Text));
  288.                 comandi.Add(5);
  289.                 textBox6.AppendText("Down Sx (" + textBox1.Text + "," + textBox2.Text + ")   ");
  290.             }
  291.             catch
  292.             {
  293.                 MessageBox.Show("I dati inseriti non sono validi. Riprova");
  294.             }
  295.         }
  296.  
  297.         private void button11_Click(object sender, EventArgs e)
  298.         {
  299.             try
  300.             {
  301.                 x.Add(Convert.ToInt32(textBox1.Text));
  302.                 y.Add(Convert.ToInt32(textBox2.Text));
  303.                 comandi.Add(6);
  304.                 textBox6.AppendText("Up Sx (" + textBox1.Text + "," + textBox2.Text + ")   ");
  305.             }
  306.             catch
  307.             {
  308.                 MessageBox.Show("I dati inseriti non sono validi. Riprova");
  309.             }
  310.         }
  311.  
  312.         private void button12_Click(object sender, EventArgs e)
  313.         {
  314.             try
  315.             {
  316.                 x.Add(Convert.ToInt32(textBox1.Text));
  317.                 y.Add(Convert.ToInt32(textBox2.Text));
  318.                 comandi.Add(7);
  319.                 textBox6.AppendText("Down Dx (" + textBox1.Text + "," + textBox2.Text + ")   ");
  320.             }
  321.             catch
  322.             {
  323.                 MessageBox.Show("I dati inseriti non sono validi. Riprova");
  324.             }
  325.         }
  326.  
  327.         private void button13_Click(object sender, EventArgs e)
  328.         {
  329.             try
  330.             {
  331.                 x.Add(Convert.ToInt32(textBox1.Text));
  332.                 y.Add(Convert.ToInt32(textBox2.Text));
  333.                 comandi.Add(8);
  334.                 textBox6.AppendText("Up dx (" + textBox1.Text + "," + textBox2.Text + ")   ");
  335.             }
  336.             catch
  337.             {
  338.                 MessageBox.Show("I dati inseriti non sono validi. Riprova");
  339.             }
  340.         }
  341.  
  342.         private void button14_Click(object sender, EventArgs e)
  343.         {
  344.             x.Add(Convert.ToInt32(textBox1.Text));
  345.             y.Add(Convert.ToInt32(textBox2.Text));
  346.             comandi.Add(9);
  347.             scriv.Add(textBox5.Text);
  348.             textBox6.AppendText("Write(" + textBox5.Text + ")   ");
  349.         }
  350.  
  351.         private void textBox5_TextChanged(object sender, EventArgs e)
  352.         {
  353.             button14.Enabled = (textBox5.Text != "");
  354.         }
  355.  
  356.         private void button15_Click(object sender, EventArgs e)
  357.         {
  358.             x.Add(Convert.ToInt32(textBox1.Text));
  359.             y.Add(Convert.ToInt32(textBox2.Text));
  360.             comandi.Add(10);
  361.             press.Add(comboBox1.Text);
  362.             textBox6.AppendText("Press " + comboBox1.Text + "   ");
  363.         }
  364.  
  365.         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  366.         {
  367.             button15.Enabled = (comboBox1.Text != "");
  368.         }
  369.  
  370.        
  371.     }
  372. }