0

I am trying to send the paste function on another form. I give that window focus and then send this message...

        PostMessage(WoWVar.WindowHandle, (uint)WM_KEYDOWN, ((IntPtr)VK_CONTROL), (IntPtr)0x1);
        PostMessage(WoWVar.WindowHandle, (uint)WM_KEYDOWN, ((IntPtr)0x56), (IntPtr)0x0);
        PostMessage(WoWVar.WindowHandle, (uint)WM_KEYUP, ((IntPtr)VK_CONTROL), (IntPtr)0x0);

I used Spy++ and manually pressed paste and I am sending the same data. The paste works fine but it leaves a trailing 'v' after everything. So if my pasted data was 'PastedData' it would send the message and it would appear like this 'PastedDatav'. I'm not sure how to avoid this?

user1127093
  • 85
  • 1
  • 3
  • 8
  • 2
    You might need a corresponding WM_KEYUP for 'V' prior to the WM_KEYUP for CTRL. Regardless, you may also want to try using the `SendKeys` API, which is more reliable anyway. – dlev Jun 28 '12 at 18:55
  • I want to send keys without having to keep focus on that window. SendKeys does not allow me to do so – user1127093 Jun 28 '12 at 19:00
  • 1
    This is never not a problem, you can't control the keyboard state with messages. Send (not post) WM_PASTE instead since that's what you really want. Or send WM_CHAR messages so you don't have to mess up the clipboard. – Hans Passant Jun 28 '12 at 19:48
  • You didn't lift the virtual finger of V key... – Daniel Mošmondor Jun 28 '12 at 20:13
  • If I post the WM_KEYUP event for the 'V' key it then adds 2 v's – user1127093 Jun 28 '12 at 21:08

0 Answers0