Send Ctrl+Key to a 3rd Party Application

流过昼夜 提交于 2019-11-30 15:51:39

问题


Im using a 3rd Party Application that exports a file. The application uses a hot key (Ctrl + E) as a shortcut for this function.

How can I send this key combination from my Delphi XE application to the 3rd Party one?


回答1:


Here is an example which shows how to send Ctrl+E to the foreground application using SendInput:

var
  Inputs: array [0..3] of TInput;
begin
  // press
  Inputs[0].Itype := INPUT_KEYBOARD;
  Inputs[0].ki.wVk := VK_CONTROL;
  Inputs[0].ki.dwFlags := 0;

  Inputs[1].Itype := INPUT_KEYBOARD;
  Inputs[1].ki.wVk := Ord('E');
  Inputs[1].ki.dwFlags := 0;

  // release
  Inputs[2].Itype := INPUT_KEYBOARD;
  Inputs[2].ki.wVk := Ord('E');
  Inputs[2].ki.dwFlags := KEYEVENTF_KEYUP;

  Inputs[3].Itype := INPUT_KEYBOARD;
  Inputs[3].ki.wVk := VK_CONTROL;
  Inputs[3].ki.dwFlags := KEYEVENTF_KEYUP;

  SendInput(Length(Inputs), Inputs[0], SizeOf(TInput));
end;

I also use a slightly modified version of SendKeys.pas from Steve Seymour. It had some problems with different keyboard layouts and is from 1999. Couldn't find it anywhere in the net.




回答2:


See question: Send keys to a twebbrowser? There is an answer there (Matt Handel) that links to an article with an example of using the SendKeys unit, and obtaining the handle of the target window.



来源:https://stackoverflow.com/questions/8429253/send-ctrlkey-to-a-3rd-party-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!