In this case keybd_event is the correct function.
It simulates key presses and key releases as if coming from a real keyboard.
Main Topics
Browse All TopicsI am using an online keyboard component that does everything I need except that it can only send a character to a Delphi component:
FLinkedControl.Perform(WM_
How can I change that line to send the character to whatever windows has the focus, like MS Word.
I tried SendMessage(GetTopWindow(0
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
The following code will open a notepad file and type DELPHI in it. of course it is
procedure TForm1.Button1Click(Sender
begin
ShellExecute(handle,'open'
{ This will write 'Delphi' and ENTER }
keybd_event(VK_SHIFT, 1, 0, 0);
keybd_event(VkKeyScan('D')
keybd_event(VkKeyScan('D')
keybd_event(VK_SHIFT, 1, KEYEVENTF_KEYUP, 0);
keybd_event(VkKeyScan('E')
keybd_event(VkKeyScan('E')
keybd_event(VkKeyScan('L')
keybd_event(VkKeyScan('L')
keybd_event(VkKeyScan('P')
keybd_event(VkKeyScan('P')
keybd_event(VkKeyScan('H')
keybd_event(VkKeyScan('H')
keybd_event(VkKeyScan('I')
keybd_event(VkKeyScan('I')
keybd_event(VK_RETURN, 1, 0, 0);
keybd_event(VK_RETURN, 1, KEYEVENTF_KEYUP, 0);
end;
The way the keyboard component I use works is as follows: for each key (other than Enter, Delete, etc...), you specify 3 values: normal, with shift, and with Alt - for example a key could be associated to (e,E,ê) - these values are stored in the component. Because of that I don't think keybd_event will work - the configuration of the TKeyboard determines what value is to be sent, not the keyboard driver (as used by keybd_event) - so it will not work for ê.
That's why I was trying with PostMessage but that does not seem to work.
Business Accounts
Answer for Membership
by: mocartsPosted on 2003-04-14 at 13:58:15ID: 8329322
try GetForegroundWindow function - it returns window with user focus: indow, WM_CHAR, ...);
SendMessage(GetForegroundW
or better use PostMessage(..) it don't wait for processing message in receiving application i.e. simply posts message in receiver queue.
wbr, mo.