Guest User

Untitled

a guest
Apr 19th, 2010
2,680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Runtime.InteropServices;
  10. using System.Threading;
  11.  
  12. namespace Send_A_Key
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         #region Imports
  17.         //RegisterHotkey
  18.         [DllImport("user32.dll")]
  19.         public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
  20.  
  21.         //UnregisterHotkey
  22.         [DllImport("user32.dll")]
  23.         public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
  24.  
  25.         //FindWindow
  26.         [DllImport("user32.dll", SetLastError = true)]
  27.         public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  28.  
  29.         //PostMessage
  30.         [return: MarshalAs(UnmanagedType.Bool)]
  31.         [DllImport("user32.dll", SetLastError = true)]
  32.         public static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
  33.  
  34.         //PostMessage
  35.         [DllImport("user32.dll")]
  36.         public static extern bool PostMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam);
  37.  
  38.         //MapVirtualKey
  39.         [DllImport("user32.dll")]
  40.         public static extern int MapVirtualKey(int uCode, uint uMapType);
  41.         #endregion
  42.  
  43.         #region Important Variables
  44.         //Set default settings in case the user is a retard
  45.         int Keycode = (int)Keys.Control;
  46.         int Delay = 100;
  47.         int Method = 0;
  48.         Thread PressShitThread;
  49.  
  50.         IntPtr hWnd;
  51.         const uint WM_KEYDOWN = 0x0100;
  52.         #endregion
  53.  
  54.         public Form1()
  55.         {
  56.             InitializeComponent();
  57.  
  58.             Object[] ComboBoxItems = new object[] {"SHIFT","CTRL","ALT","SPACE","END","HOME","INS","DEL","0","1","2","3","4","5","6","7","8","9","A","B",
  59.             "C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
  60.             comboBox1.Items.AddRange(ComboBoxItems);
  61.  
  62.             RegisterHotKey(Handle, 9001, 0, (uint)Keys.F9);
  63.         }
  64.  
  65.         protected override void WndProc(ref Message m)
  66.         {
  67.             base.WndProc(ref m);
  68.             switch (m.Msg)
  69.             {
  70.                 case 0x312:
  71.                     switch ((int)m.WParam)
  72.                     {
  73.                         case 9001: checkBox1.Checked ^= true;
  74.                             break;
  75.                     }
  76.                     break;
  77.             }
  78.         }
  79.  
  80.         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  81.         {
  82.             if (comboBox1.Text.Length == 1)
  83.             {
  84.                 char c;
  85.                 char.TryParse(comboBox1.Text, out c);
  86.                 Keycode = (int)c;
  87.             }
  88.             else
  89.             {
  90.                 switch (comboBox1.SelectedIndex)
  91.                 {
  92.                     case 0: Keycode = (int)Keys.Shift;
  93.                         break;
  94.                     case 1: Keycode = (int)Keys.Control;
  95.                         break;
  96.                     case 2: Keycode = (int)Keys.Alt;
  97.                         break;
  98.                     case 3: Keycode = (int)Keys.Space;
  99.                         break;
  100.                     case 4: Keycode = (int)Keys.End;
  101.                         break;
  102.                     case 5: Keycode = (int)Keys.Home;
  103.                         break;
  104.                     case 6: Keycode = (int)Keys.Insert;
  105.                         break;
  106.                     case 7: Keycode = (int)Keys.Delete;
  107.                         break;
  108.                 }
  109.             }
  110.         }
  111.  
  112.         private void textBox1_TextChanged(object sender, EventArgs e)
  113.         {
  114.             int Temp;
  115.             if (int.TryParse(textBox1.Text, out Temp) && Temp > 1)
  116.             {
  117.                 Delay = Temp;
  118.             }
  119.         }
  120.  
  121.         private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
  122.         {
  123.             Method = comboBox2.SelectedIndex;
  124.         }
  125.  
  126.         private void checkBox1_CheckedChanged(object sender, EventArgs e)
  127.         {
  128.             if (checkBox1.Checked)
  129.             {
  130.                 PressShitThread = new Thread(new ThreadStart(PressShit));
  131.                 PressShitThread.Start();
  132.             }
  133.             else
  134.             {
  135.                 PressShitThread.Abort();
  136.             }
  137.         }
  138.  
  139.         void PressShit()
  140.         {
  141.             LOOP:
  142.             if (Method == 0)
  143.             {
  144.                 if (hWnd == IntPtr.Zero)
  145.                 {
  146.                     hWnd = FindWindow("MapleStoryClass", null);
  147.                 }
  148.                 PostMessage(hWnd, WM_KEYDOWN, Keycode, MapVirtualKey(Keycode, 0) << 16);
  149.             }
  150.             else
  151.             {
  152.                 SIClass.SendKeyAsInput(Keycode);
  153.             }
  154.             Thread.Sleep((int)Delay);
  155.             goto LOOP;
  156.         }
  157.     }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment