2

i have been having a hard time to find anything that is usefull but i found someone asked how to do that,(How to send keystrokes to a window?)

if used the code and i can set notepad's text but i want to send keys but sets the text, i want to send keys like keybd_event i have been using it but i want to only have it send to one program.

keybd_event('a', NULL, NULL, NULL);  
keybd_event('a', NULL, KEYEVENTF_KEYUP, NULL); 

how could i do that?

Community
  • 1
  • 1
blood
  • 746
  • 5
  • 13
  • 22
  • I have added the win32/windows tag. If windows is not the OS, please re-edit to update the right one. –  Feb 23 '10 at 02:32
  • (1) Do you need to be able to send to any program at all, or do you have a particular set of programs in mind? (2) Have you looked at AutoHotKey? It's a standalone app (so no C++ interface) but it is often used to perform this kind of task. – jdigital Feb 23 '10 at 02:50
  • moron: xD tyvm for adding the tag sorry i did not think of it. jdigital: just the program i choose by the handle. autoHotkey i have not looked at but there has to be someway i can send it to only one program. my program is just a console window i don't really care about the window because it does nothing, i might just hide it but idk. – blood Feb 23 '10 at 05:29
  • Does the program accept input on stdin? If so, then instead of sending keystrokes, you may be able to pipe in your data. – jdigital Feb 23 '10 at 18:07

1 Answers1

0

Sounds like you're trying to make a window have the focus before sending your keys. Look at FindWindow and SetForegroundWindow.

Something like this should work:

SetForegroundWindow(FindWindow(0,"Untitled - Notepad"));
keybd_event(....);

If instead you're talking about changing a window's text directly, look at GetWindow to navigate the window tree and SendMessage with a WM_SETTEXT parameter.

Blindy
  • 65,249
  • 10
  • 91
  • 131