Omar Almusalhi

Omar Almusalhi

  • NA
  • 1
  • 1.1k

Send mouse motions using SendMessage()

Mar 5 2015 5:11 AM
Hi all,,
I was reading about sending a mouse motion to for example Notepad..
I tried to implement something to help me send a right click to Notepad so when the event fired it shows that there is a right click fired and the right click menu appears in the notepad..

I wrote this code but I'm not sure it's correct -no error but it doesn't work..

// to send the mouse Message
 [DllImport("user32.dll")] public static extern int SendMessage(int hWnd,uint Msg, int wParam,int lParam);

// mouse input 
 private const uint WM_RBUTTONDOWN = 0x0204; 
private const uint WM_RBUTTONUP = 0x0205;

// event handler
private void button6_Click(object sender, EventArgs e) { int window = FindWindow(null, "Notepad"); {
SendMessage(window, WM_RBUTTONDOWN, 0, 0); 
SendMessage(window, WM_RBUTTONUP, 0, 0); }
}

Thanks in advance :)