Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using System.Threading;
- namespace Send_A_Key
- {
- public partial class Form1 : Form
- {
- #region Imports
- //RegisterHotkey
- [DllImport("user32.dll")]
- public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
- //UnregisterHotkey
- [DllImport("user32.dll")]
- public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
- //FindWindow
- [DllImport("user32.dll", SetLastError = true)]
- public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
- //PostMessage
- [return: MarshalAs(UnmanagedType.Bool)]
- [DllImport("user32.dll", SetLastError = true)]
- public static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
- //PostMessage
- [DllImport("user32.dll")]
- public static extern bool PostMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam);
- //MapVirtualKey
- [DllImport("user32.dll")]
- public static extern int MapVirtualKey(int uCode, uint uMapType);
- #endregion
- #region Important Variables
- //Set default settings in case the user is a retard
- int Keycode = (int)Keys.Control;
- int Delay = 100;
- int Method = 0;
- Thread PressShitThread;
- IntPtr hWnd;
- const uint WM_KEYDOWN = 0x0100;
- #endregion
- public Form1()
- {
- InitializeComponent();
- Object[] ComboBoxItems = new object[] {"SHIFT","CTRL","ALT","SPACE","END","HOME","INS","DEL","0","1","2","3","4","5","6","7","8","9","A","B",
- "C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
- comboBox1.Items.AddRange(ComboBoxItems);
- RegisterHotKey(Handle, 9001, 0, (uint)Keys.F9);
- }
- protected override void WndProc(ref Message m)
- {
- base.WndProc(ref m);
- switch (m.Msg)
- {
- case 0x312:
- switch ((int)m.WParam)
- {
- case 9001: checkBox1.Checked ^= true;
- break;
- }
- break;
- }
- }
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (comboBox1.Text.Length == 1)
- {
- char c;
- char.TryParse(comboBox1.Text, out c);
- Keycode = (int)c;
- }
- else
- {
- switch (comboBox1.SelectedIndex)
- {
- case 0: Keycode = (int)Keys.Shift;
- break;
- case 1: Keycode = (int)Keys.Control;
- break;
- case 2: Keycode = (int)Keys.Alt;
- break;
- case 3: Keycode = (int)Keys.Space;
- break;
- case 4: Keycode = (int)Keys.End;
- break;
- case 5: Keycode = (int)Keys.Home;
- break;
- case 6: Keycode = (int)Keys.Insert;
- break;
- case 7: Keycode = (int)Keys.Delete;
- break;
- }
- }
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- int Temp;
- if (int.TryParse(textBox1.Text, out Temp) && Temp > 1)
- {
- Delay = Temp;
- }
- }
- private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
- {
- Method = comboBox2.SelectedIndex;
- }
- private void checkBox1_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox1.Checked)
- {
- PressShitThread = new Thread(new ThreadStart(PressShit));
- PressShitThread.Start();
- }
- else
- {
- PressShitThread.Abort();
- }
- }
- void PressShit()
- {
- LOOP:
- if (Method == 0)
- {
- if (hWnd == IntPtr.Zero)
- {
- hWnd = FindWindow("MapleStoryClass", null);
- }
- PostMessage(hWnd, WM_KEYDOWN, Keycode, MapVirtualKey(Keycode, 0) << 16);
- }
- else
- {
- SIClass.SendKeyAsInput(Keycode);
- }
- Thread.Sleep((int)Delay);
- goto LOOP;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment