pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

C# pastebin - collaborative debugging tool View Help


Posted by Connor on Sat 22 Aug 22:43 (modification of post by view diff)
report abuse | View followups from Sneak, EagleWingProd, Jacob and Anonymous | download | new post

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Runtime.InteropServices;
  9. //InteropServices is what allows us to use DllImport        
  10.  
  11. namespace ExampleBot
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.  
  16.         //FindWindow
  17.         [DllImport("user32.dll", SetLastError = true)]
  18.         static extern IntPtr FindWindow(
  19.             string lpClassName,
  20.             string lpWindowName);
  21.  
  22.         //hWnd to make it easier
  23.         IntPtr hWnd = FindWindow(
  24.             null,
  25.             "MapleStory");
  26.  
  27.         //PostMessage
  28.         [return: MarshalAs(UnmanagedType.Bool)]
  29.         [DllImport("user32.dll", SetLastError = true)]
  30.             static extern bool PostMessage(
  31.             IntPtr hWnd,
  32.             uint Msg,
  33.             int wParam,
  34.             int lParam);
  35.         //Define WM_KEYDOWN
  36.             const int WM_KEYDOWN = 0x100;
  37.  
  38.         public Form1()
  39.         {
  40.             InitializeComponent();
  41.         }
  42.  
  43.         private void chksendkey_CheckedChanged(object sender, EventArgs e)
  44.         {
  45.             tmrsendkey.Enabled ^= true;
  46.             // ^= is xor. This means that if it's false, it will become true. If it's true, it will become false. (Opposite)
  47.         }
  48.  
  49.         private void txtdelay_TextChanged(object sender, EventArgs e)
  50.         {
  51.             tmrsendkey.Interval = Convert.ToInt32(txtdelay.Text);
  52.             //You must convert to an int because txtdelay.Text is a string and it won't convert itself :3
  53.         }
  54.  
  55.         private void Form1_Load(object sender, EventArgs e)
  56.         {
  57.             FindWindow(null, "MapleStory");
  58.             /* null would be where the Window Class would be.
  59.              * Which is MapleStoryClass for MS. But apparently the class
  60.              * when the 'play screen' is up isnt' MapleStoryClass,
  61.              * and I like opening my stuff at the play screen.
  62.              * So I just used the Window Name instead.
  63.              */
  64.         }
  65.  
  66.         private void tmrsendkey_Tick(object sender, EventArgs e)
  67.         {
  68.             PostMessage(hWnd, WM_KEYDOWN, 0x41, 0x1e0001);
  69.             //0x41 is wParam and 0x1e0001 is lParam
  70.             //You can find a list of these at http://pastebin.com/f6c1db818
  71.  
  72.         }
  73.     }
  74. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post