Analog keyboard in C #

Source: Internet
Author: User
Tags foreach bool flush readline sleep thread

A while ago crazy fascinated by the World of Warcraft, Crazy for it, but 9c 5 district, let how many players depressed Ah, the sword of the Guardian line every day 800+, but also non-stop card machine, off line, I office workers, every night 6 o'clock work to go home to line up, on-line also are more than 8 o'clock, MC Ah, black e ah, aql ah and so on activities early start, It's very depressing!

In order to play the game on time, the Spirit of Warcraft in the end of the principle, decided to develop a Warcraft automatic landing to solve the immediate problem, haha!

First define a class viastruct, to store the game path, wait time, and user name, password!

using System;


using System.Collections.Generic;


using System.Text;


using System.IO;


using System.Windows.Forms;


using System.Threading;


using System.Diagnostics;


namespace Keyboardinput


{


[Serializable]


public class Viastruct


  {


private String timer = "";


private String filepath = "";


private String username = "";


private string pwd = "";


private String timer2 = "";


public bool Successflag = FALSE;


public viastruct ()


{


Successflag=readformkbi ();


    }


#region Properties


public string Timer


    {


get {return timer;}


set {timer = value;}


    }


public string FilePath


    {


get {return filepath;}


set {filepath = value;}


    }


public string UserName


    {


get {return username;}


set {username = value;}


    }


public string Pwd


    {


get {return pwd;}


set {pwd = value;}


    }


public string Timer2


    {


get {return timer2;}


set {timer2 = value;}


    }


#endregion


private bool Readformkbi ()


    {


StreamReader sr = new StreamReader ("Info.txt");


if (This.filepath = Sr. ReadLine ()) = = NULL | | This.filepath = "")


      {


return false;


      }


This.timer = Sr. ReadLine ();


this.timer2 = Sr. ReadLine ();


this.username = Sr. ReadLine ();


this.pwd = Sr. ReadLine ();


Sr. Close ();


Sr. Dispose ();


GC. Collect ();


return true;


    }


public void Writetokbi ()


    {


thread th = new Thread (new ThreadStart (Newmethod));


th. Start ();


    }


private void Newmethod ()


    {


Try


{


StreamWriter sw = new StreamWriter ("Info.txt");


SW. WriteLine (This.filepath);


SW. Flush ();


SW. WriteLine (This.timer);


SW. Flush ();


SW. WriteLine (THIS.TIMER2);


SW. Flush ();


SW. WriteLine (This.username);


SW. Flush ();


SW. WriteLine (THIS.PWD);


SW. Flush ();


SW. Close ();


MessageBox.Show ("Write success!");


      }


catch (Exception ex)


      {


MessageBox.Show (ex. message);


      }


    }


  }


}


  


then write the Form1 window


using System;


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.Threading;


namespace Keyboardinput


{


public partial class Form1:form


  {


Viastruct via;


Thread th;


Thread ti;


public Form1 ()


    {


InitializeComponent ();


via = new Viastruct ();


    }


private void Form1_Load (object sender, EventArgs e)


    {


This.textBox1.Text = via. UserName;


This.textBox2.Text = via. PWD;


This.textBox3.Text = via. FilePath;


This.textBox4.Text = via. Timer2;


This.comboBox1.Text = Via. Timer;


th = new Thread (new ThreadStart (Newmethod));


th. Start ();


    }


private void Newmethod ()


    {


if (via. Successflag)


      {


Try


        {


Thread.Sleep (Convert.ToInt32 convert.todecimal (via. Timer) * 60 * 1000))//Open the program and wait for


//via. Start Program
in timer time

Process.Start (via. FilePath);


Thread.Sleep (Convert.ToInt32 convert.todecimal (via. TIMER2) * 60 * 1000));//Start the program and wait for//via. Timer2 time to enter user name password


        }


catch (Exception ex)


        {


if (ex. GetType (). ToString ()!= "System.Threading.ThreadAbortException")


MessageBox.Show (ex. Message+ "1");


        }        


      }


if (via. Successflag)


      {


Mysendkeys ();


      }


    }


private void Button1_Click (object sender, EventArgs e)


    {


this.openFileDialog1.RestoreDirectory = true;


if (this.openFileDialog1.ShowDialog () = = DialogResult.OK)


      {


this.textBox3.Text = this.openFileDialog1.FileName;


      }


//MessageBox.Show (environment.currentdirectory);


    }


private void Notifyicon1_doubleclick (object sender, EventArgs e)


    {


this. Show ();


    }


private void Form1_minimumsizechanged (object sender, EventArgs e)


    {


this. Visible = false;


    }


private void Mysendkeys ()/Enter user name password


    {


foreach (char arrayvalue in Via. Username.tochararray ())


      {


sendkeys.sendwait (arrayvalue.tostring ());


Thread.Sleep (10);


      }


sendkeys.sendwait ("{tab}");


foreach (char arrayvalue in Via. Pwd.tochararray ())


      {


sendkeys.sendwait (arrayvalue.tostring ());


Thread.Sleep (10);


      }


sendkeys.sendwait ("{Enter}");


    }


private void Button2_Click (object sender, EventArgs e)//is assigned to the Via object


    {


via. Timer = This.comboBox1.Text;


Via. Timer2 = This.textBox4.Text;


via.     FilePath = This.textBox3.Text;


via. UserName = This.textBox1.Text;


via. PWD = This.textBox2.Text;


via.      Writetokbi ();


    }


private void Form1_formclosing (object sender, FormClosingEventArgs e)//After closing the window to eject the thread


    {


if (th. ThreadState!= System.Threading.ThreadState.Aborted)


th. Abort ();


if (ti!=null&&ti. ThreadState!=system.threading.threadstate.aborted)


ti. Abort ();


    }


private void Button3_Click (object sender, EventArgs e)


    {


th. Abort ();


ti = new Thread (new ThreadStart (prograssimmediately));


ti. Start ();


    }


private void prograssimmediately ()


    {


if (via. Successflag)


      {


Try


        {


Process.Start (via. FilePath);


Thread.Sleep (Convert.ToInt32 convert.todecimal (via. TIMER2) * 60 * 1000));


        }


catch (Exception ex)


        {


//messagebox.show (ex. GetType (). ToString ());


if (ex. GetType (). ToString ()!= "System.Threading.ThreadAbortException")


MessageBox.Show (ex. Message + "1");


        }


      }


if (via. Successflag)


      {


Mysendkeys ();


      }


    } 


  }


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.