Click to See Complete Forum and Search --> : howto send keyboard input to the active application??


kalle
April 1st, 1999, 03:07 AM
How can I 'feed' the active application (the active window) with virtual keyboard input from an background task?


thanks for your halp


K.

Simon Pettman
April 1st, 1999, 03:19 AM
Surely if the background app is sending the appropriate messages, you can retrieve them within the active app in the normal way.


Simon P.

Dazza
April 1st, 1999, 03:38 AM
Try using ::SendMessage(hWndActive,WM_CHAR,nCharCode,nData);


If nData is between 1 and 15, it is the number of repeats of the character

(see the help on WM_CHAR for the other values).

kalle
April 1st, 1999, 07:03 AM
Yes, but how do I get the HWND of the active application?


And..

.. can I send it to the main window, or do I have to send it th the active window?


Thanks


K.

Dazza
April 1st, 1999, 08:37 AM
It really depends on exactly what you want to do. To get the active window, try using GetForegroundWindow(), to find a specific application window, try using FindWindow(...)

kalle
April 1st, 1999, 11:47 AM
I tried it, but it doesn't work.


Here ist the code:


HWND hW;

hW=::GetForegroundWindow ();

m_nResult=::SendMessage (hW,WM_CHAR,'X',1);


So why does't it work???

Rob
April 1st, 1999, 02:38 PM
You should use the keybd_event API call. This function
sends the specified keystroke to the window that currently has
the input focus.
The keybd_event API call has four parameters:

BYTE VKeyCode, BYTE ScanCode, DWORD flags, DWORD ExtraInfo

I just used the first two parameters, and it seemed to work fine...

rob
April 1st, 1999, 02:38 PM
You should use the keybd_event API call. This function
sends the specified keystroke to the window that currently has
the input focus.
The keybd_event API call has four parameters:

BYTE VKeyCode, BYTE ScanCode, DWORD flags, DWORD ExtraInfo

I just used the first two parameters, and it seemed to work fine...

kalle
April 2nd, 1999, 03:30 AM
Hi Rob,
I tried it and it seems to work fine.
But all output is in lower case.
And for what do I need the 'ScanCode'?

Rob
April 2nd, 1999, 08:22 AM
The scan code is for the "OEM-dependent hardware scan code". Most applications don't use this scan code. The documentation says that the system converts this guy to a virtual key code anyway.

As far as case goes, you have to send a different virtual key code to specify case. For example:

f - 102
F - 70

Hope this helps:)

rob
April 2nd, 1999, 08:22 AM
The scan code is for the "OEM-dependent hardware scan code". Most applications don't use this scan code. The documentation says that the system converts this guy to a virtual key code anyway.

As far as case goes, you have to send a different virtual key code to specify case. For example:

f - 102
F - 70

Hope this helps:)