Closed Francesco149 closed 9 years ago
here is code a simple text entry system that will let you use the keyboard. I don't have time to integrate it into the git, but here is my sample.
import win32con
import win32api
import win32gui
def enumHandler(hwnd, lParam):
if win32gui.IsWindowVisible(hwnd):
if 'testwindowinfo' in win32gui.GetWindowText(hwnd):
for c in "Hello World\n":
win32api.PostMessage(
hwnd,
win32con.WM_CHAR,
ord(c),
0)
win32gui.EnumWindows(enumHandler, None)
This finds a window with the name 'testwindowinfo' in it and posts 'Hello World' to it
Why does it only work for certain games and not all? Is it an emulator limitation or a game issue?
That being said I will add this into my fork.
I think it depends on how the game handles the input. For example, it doesn't work for VisualBoyAdvance (which also seems to have system-wide input, as it will register input from other windows even when minimized), but it works on MapleStory. I think it only works on games or engines that use the win32 message loop to handle input but I'm not entirely sure.
Your solution @tcsnyder in your fork produces errors.
win32gui.EnumWindows(self.enumHandler, winlist)
TypeError: enumHandler() takes exactly 2 arguments (3 given)
@Francesco149 @tcsnyder I have posted my solution but it doesn't seem to register a post message.
It only works with games that use the Win32 message queue to process keystrokes. So far I've only used it on bots for MapleStory.
Some games will register keystrokes from PostMessage which sends a keystroke only to a certain window, even if it's hidden or minimized. This could avoid using a VM to stream certain games. I used to use this to make MMO bots to keep using your PC even while you're botting.
c++ example: