0

My issue currently is that of emulating keystroke input to an arbitrary program (such as a running game).

Currently I am using win32 libraries on Windows to find windows (win32gui.FindWindow) and grab focus (via win32gui.SetForegroundWindow), then send keyboard input (win32api.keybd_event).

This works if I am only sending input to a single program, but I wish to parallelize, playing multiple games simultaneously. This does not work with my current method as both applications demand "focus" for the keys to go to the right application, thus interfering with each other.

Ideally I would like something that sends input to a given window, that does not require focus , and is independent of input given to other windows or the currently focused window.

Nix
  • 66
  • 3
  • http://stackoverflow.com/questions/21917965/send-keys-to-a-inactive-window-in-python – Mihail Kuznesov Mar 29 '17 at 04:45
  • Unfortunately, this program does not have an "edit" child like notepad, and does not recognize key inputs sent through sendmessage and postmessage. – Nix Mar 30 '17 at 23:08
  • You no need "edit" child. Simply send message to main window of this application. Edit child just important for notepad, but sendmessage work for any Windows programm – Mihail Kuznesov Mar 31 '17 at 11:57
  • You can use any like spy++ utility for windows, to check internal of window application, do you need 'edit' child or not. http://stackoverflow.com/questions/4088368/spy-alternative-that-can-send-messages this link also not direct answer to your question, but this utilities can help you, if you want. :) – Mihail Kuznesov Mar 31 '17 at 12:03
  • You can start to read from this: https://msdn.microsoft.com/en-us/library/windows/desktop/ff381405(v=vs.85).aspx this article explain how messages work in windows. P.S. This link also not answer to your question, it just will give you understanding how sendmessage and other messaging functions work – Mihail Kuznesov Mar 31 '17 at 12:06
  • "application must respond to events from the user and from the operating system. Events from the user include all of the ways that someone can interact with your program: mouse clicks, key strokes, touch-screen gestures, and so forth." from Microsoft explanation of messaging. Application **MUST** respond to message. It is base mechanism of Windows – Mihail Kuznesov Mar 31 '17 at 12:26

1 Answers1

-1

My understanding is, only the foreground window get the focus and can handle keyboard input to play. Not sure in make sense to send input to background window or not....

Jerryhcc
  • 1
  • 1
  • By sendmessage and postmessage you can send keyboard and mouse events to background program. http://stackoverflow.com/questions/11890972/simulating-key-press-with-postmessage-only-works-in-some-applications http://stackoverflow.com/questions/21917965/send-keys-to-a-inactive-window-in-python https://msdn.microsoft.com/ru-ru/library/windows/desktop/ms644950(v=vs.85).aspx – Mihail Kuznesov Mar 29 '17 at 11:02