hacer

Hi i have a problem. I want to write a program that would send a keystroke to other window. Do i have to use hooks or there are some other ways. I saw some that uses .Net Framework. Desired OS don't have Net Framework installed.



Re: Visual C++ Language Sending keystrokes to other window

Simple Samples

More informatin would help.

Are you using MFC

Is the window in the same process or is it a different process

The main reason I ask those questions is because there are alternative ways to control a window than sending keystrokes. People often think that sending keystrokes is an easy solution, but there are many unanticipated details that make it difficult to get it right. Are you sure you must send keystrokes If you must, then please See Windows SDK forum for Windows programming questions.






Re: Visual C++ Language Sending keystrokes to other window

einaros

Use SendInput or a combination of SendMessage and WM_KEYDOWN / WM_KEYUP.

Redirect further questions elsewhere, as Sam says.






Re: Visual C++ Language Sending keystrokes to other window

Simple Samples

 einaros wrote:

Use SendInput or a combination of SendMessage and WM_KEYDOWN / WM_KEYUP.

It's not that easy. It is also necessary to ensure that the control or whatever window the input is intended for has the focus. I have not tried it myself, but others that have tried it I think have had problems with timing. The timing can probably be solved by Sleep but I am not sure of that.




Re: Visual C++ Language Sending keystrokes to other window

einaros

 Simple Samples wrote:
It's not that easy. It is also necessary to ensure that the control or whatever window the input is intended for has the focus. I have not tried it myself, but others that have tried it I think have had problems with timing. The timing can probably be solved by Sleep but I am not sure of that.

I've done this a gazillion times, so I'm quite aware of what's involved. Telling the OP that those are the possible paths does help him along, however off topic the question may be. Including a full code sample would be overkill.

There are articles on the matter, which may prove helpful if you dive into the source code:






Re: Visual C++ Language Sending keystrokes to other window

Simple Samples

einaros wrote:
I've done this a gazillion times, so I'm quite aware of what's involved. Telling the OP that those are the possible paths does help him along, however off topic the question may be. Including a full code sample would be overkill.
Yes it is not easy to be sure how much to say. I agree that we want to encourage use of more relevant forums and newsgroups, and I know you know that I do that often. I think it does help however to provide an indication of what is required; my intent is to explain that there could be an easier way, even though the alternatives might seem more complicated.




Re: Visual C++ Language Sending keystrokes to other window

hacer

I used kebd_event, SendInput(). Target window is written in C++ Builder (or Delphi i'm not sure) and it's not working. I tested my program on Notepad and its ok. How to use it with program made in C++Builder





Re: Visual C++ Language Sending keystrokes to other window

Simple Samples

The language used by the target application should not matter. You should review the answers already provided here, especially the answers from Einar. If that does not help, then you need to use a newsgroup or another forum to get further help from.




Re: Visual C++ Language Sending keystrokes to other window

Noz3001-

The window doesn't need keyboard focus for SendMessage unlike SendInput.




Re: Visual C++ Language Sending keystrokes to other window

Noz3001-

If it's something like an online game, theres a chance that SendInput & SendMessage are hooked.




Re: Visual C++ Language Sending keystrokes to other window

Rosh K Mathews

Very helpful article. Thanks.

Rosh K M