Send CTRL+V via Postmessage

Asked

Viewed 1,063 times

2

Hello, I need to send click combination CTRL+V via POSTMESSAGE. I tried to do it this way:

 PostMessage(h,WM_KEYDOWN,VK_CONTROL,0);
 PostMessage(h,WM_KEYDOWN,VK_V,0); (Ele da erro nessa linha diz que o VK_V não existe)
 PostMessage(h,WM_KEYDOWN,VK_CONTROL,1);
 PostMessage(h,WM_KEYDOWN,VK_V,1);

What could I be doing wrong ?

2 answers

2


You can do this by sending the message WM_PASTE to the Handle out the window like this:

var
  appHandle: HWND;
begin
 appHandle := FindWindow(nil, 'TitulodaJanela');
 if appHandle = 0 then // Se não encontrou a janela
   exit; 
 PostMessage(appHandle, WM_PASTE, 0, 0);
  • i tested this way, it does not glue.... if I give CTRL + V it glue straight, more with POSTMESSAGE will not...some other suggestion ?

  • I do not know why, the second command, it appears the letter V on the other side...because it will be ? and not glue...

  • Okay @Sunstreaker, thanks for your help!

  • Yes I have @Sunstreaker, because if I give a CTRL + V on the machine it glue normal.. strange right ?

  • 1

    it worked yes...the Handle was wrong! Thanks friend!

1

According to the the MSDN website, there is no constant for the alphabetical keys, so use the hexadecimal value directly.

In this case, to simulate pressing the V key use the value 0x56.

  • then it would look like this: Postmessage(h,WM_KEYDOWN,VK_CONTROL,1); Postmessage(h,WM_KEYDOWN,56,1); I did so it appears the number 8 on the screen already saw it ? rsrsrss

  • @user7605 you wrote the number as decimal, should put 0x in front, which means you are passing as hexadecimal; 56 in decimal corresponds to 0x38, which is value corresponding to Virtual Key of key 8.

  • if I put Postmessage(h,WM_KEYDOWN,0x56,1); it does not accept, error.

  • @user7605 I didn’t quite understand what you want with your application, maybe the error is not in this specific function, anyway, give us more details of the error occurred. Alternatively if you want to test with the number 0x56 represented in decimal place PostMessage(h,WM_KEYDOWN,86,1);

  • is a remote application where employees connect to a server via socket. I did so: Postmessage(h,WM_KEYDOWN,VK_CONTROL,1); Postmessage(h,WM_KEYDOWN,86,1); Instead of giving CTRL+V on the system, it appears the letter "v" rsrsrsrsrsrs...

  • @user7605 in your question you put PostMessage(h,WM_KEYDOWN,VK_CONTROL,0); come before, now in the comment you put PostMessage(h,WM_KEYDOWN,VK_CONTROL,1); come before. I have no way to use an IDE now to test, but you don’t think you reversed when CTRL is pressed and released?

  • thanks for the effort... i also thought that was it, I tidied up now and even so it inserts 2x the letter V...I saw a command on the NET that says to use the following: Postmessage(AHWND, WM_PASTE, 0, 0);, even so it is not right.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.