Advertisement
Guest User

SendCommand

a guest
Aug 25th, 2011
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1.         [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
  2.         static extern IntPtr FindWindowByCaption(int ZeroOnly, string lpWindowName);
  3.  
  4.         [DllImport("user32.dll", CharSet = CharSet.Auto)]
  5.         static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, int wParam, IntPtr lParam);
  6.  
  7.         const int WM_KEYDOWN = 0x100;
  8.         //const int WM_KEYUP = 0x101;
  9.         const int L_KEY = 0x4C;
  10.  
  11.         private void button1_Click(object sender, EventArgs e)
  12.         {
  13.             IntPtr ip = FindWindowByCaption(0, "Untitled - Notepad");
  14.  
  15.             SendMessage(ip, WM_KEYDOWN, L_KEY, IntPtr.Zero);
  16.             //SendMessage(ip, WM_KEYUP, L_KEY, IntPtr.Zero);
  17.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement