
#win.SendMessage(win32con.WM_KEYUP, 0x1E, 0) #win.SendMessage(win32con.WM_KEYDOWN, 0x1E, 0) #win.SendMessage(win32con.WM_CHAR, ord('B'), 0) #win.SendMessage(win32con.WM_CHAR, ord('A'), 0) Win = win32ui.CreateWindowFromHandle(hwnd) Hwnd = win32gui.FindWindow(None, window_name) Import win32gui, win32ui, win32con, win32api I first tested a simple example with Notepad, and this gave me more problems than I was expecting. So let's try it out and see what we can do with it. It's a Windows API function he was calling via pywin32, and it allows you to send messages, including mouse and keyboard inputs, to a specific window.Īnd there's a couple StackOverflow discussions about SendMessage(), but other than that, there really isn't a whole lot I could find about working with this. You might be able to find better performance by setting up hardware graphics acceleration for your VM, but that's not the route I decided to explore today.Ībout a year ago now, as I was working on my OpenCV series, I got a tip from a viewer telling me about this SendMessage() function he was using to send inputs to a window in the background. At least with Hyper-V, even basic games show considerable lag.

I've confirmed that this does work, but the problem is the performance of virtual machines is typically not very good. You could have multiple VM's running in the background and those would be isolated from whatever you're doing on your main desktop. I'm guessing most of you want to know how to do this because you've written a bot, and you want to run multiple bots at once, or you want your bot to run in the background while you continue using your computer.Īnd my initial reaction when I started getting this question was: just use virtual machines.


Today I want to answer the most asked question on my channel: I'll share my progress and discuss the suitability of using this method for botting. Let's explore using SendMessage to send automated inputs to multiple windows at once, or to windows that are minimized or in the background.
