How can I 'feed' the active application (the active window) with virtual keyboard input from an background task?
thanks for your halp
K.
Printable View
How can I 'feed' the active application (the active window) with virtual keyboard input from an background task?
thanks for your halp
K.
Surely if the background app is sending the appropriate messages, you can retrieve them within the active app in the normal way.
Simon P.
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).
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.
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(...)
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???
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...
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...
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'?
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:)
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:)