How can I send direct input to games, specifically Roblox, using Python? - python

I've been trying to use Python to send inputs to Roblox, but to no avail. What I know so far is that Roblox requires DirectInput, as most games do.
I've seen people successfully send keystrokes, but haven't seen any example of mouse movements or mouse clicks; to complete my goal, I need to be able to move the mouse, send clicks, as well as keyboard inputs, to an active Roblox window.
I'm currently using Python 3.9, if that's of any help.

Related

send mouse/keyboard inputs to active/inactive windows

I use python and pynput to automate my mouse.
But obviously, it is impossible to use the computer at the same time for other things. So I'm looking for a solution to either automate a "second" virtual mouse or to just send mouse clicks to a specific window (active or inactive) on Windows 10 without actually using the real mouse.
You can use pyautogui to automate keyboard and mouse actions; but if you are using the keyboard and mouse it will interfere with these commands. the same could be said about adding another mouse; it doesn't add a second OS pointer; it only creates another (at times conflicting) control over that pointer.

How to run mouse and keyboard events in a minimized window

I am looking for a way to run mouse and keyboard events in a minimized window, simple as that - the code does something in a specific window, while my computer is free - I can search the web and do whatever; I need Python 2 specifically, but open for 3 suggestions too; This is for automatization of certain tasks I have, I managed to make it work while my computer is in use, but now I need to run it in the background.
Thank you in advance.

How do I simulate a keypress so that SDL will pick up on it

I have been trying to find a method to simulate a keypress from python, it works when sending it to an x server, It can type in any part except it seems SDL,I am trying to send keypresses to mupen64plus, xdotools doesn't work, xsendkey doesn't work, uinput python module doesn't work.
I can send them to the desktop (ie terminal or gedit) it's just not picking up on the keypresses inside mupen - I think it has got to do with SDL reading /dev/input/
Does anyone have any pointers, is there anyway I can implement this in python, I haven't been able to find a way to simulate hardware keypresses either.

Use Python win32api module to control Steam games

I am making a gyro mouse. The driver script reads sensor input and moves mouse accordingly with win32api commands.
win32api.SetCursorPos((xStart-int(dh*xsensitivity),ypos))
When I open a full screen game such as Counter Strike Source, the mouse wont work at all. Only the click inputs function, but they cause to gun to point straight down and perform a kind of seizure.
Is there some way I can interface with whatever controls the mouse inside the game?
I'm not terribly familiar with Windows programming, but my best guess is that the video game (Counter Strike) is using the DirectInput (from DirectX) methods to read mouse travel. That is, it's using DirectInput to get mouse motion events, and the Python win32api.SetCursorPos is "warping" the cursor to the given location and not generating ANY intermediate movement messages.
You'll most likely need to use the MS Win32 API call SendInput to construct mouse movement messages and push them into the event queue at the OS level.
If you're familiar with .NET technologies, you might try using IronPython (a Python interpreter that can interact with the .NET runtime). In such case, the Input Simulator project at Codeplex has methods defined for pushing mouse movement events into the input queue.

Precise response to tablet/mouse events in Windows

How can I tell Windows not to do unhelpful pre-processing on tablet pen events?
I am programming in Python 2.6, targetting tablet PCs running Windows 7 (though I would like my program to work with little modification on XP with a SMART interactive whiteboard, and for mouse users on Linux/Mac). I've written a program which hooks into the normal Windows mouse events, WM_MOUSEMOVE etc., and writes on a canvas.
The problem is that the mouse messages are being fiddled with before they reach my application. I found that if I make long strokes and pause between strokes then the mouse messages are sent properly. But if I make several rapid short strokes, then something is doing unhelpful pre-processing. Specifically, if I make a down-stroke about 10 pixels long, and then make another downstroke about five pixels to the right of the first, then the second WM_MOUSEDOWN reports that it comes from exactly the same place as the first.
This looks like some sort of pre-processing, perhaps so that naive applications don't get confused about double-clicks. But for my application, where I want very faithful response to rapid gestures, it's unhelpful.
I found a reference to the MicrosoftTabletPenServiceProperty atom, and to CS_DBLCLKS window style, and I turned them both off with the following piece of Python code:
hwnd = self.GetHandle()
tablet_atom = "MicrosoftTabletPenServiceProperty"
atom_ID = windll.kernel32.GlobalAddAtomA(tablet_atom)
windll.user32.SetPropA(hwnd,tablet_atom,1)
currentstyle = windll.user32.GetClassLongA(hwnd, win32con.GCL_STYLE)
windll.user32.SetClassLongA(hwnd, win32con.GCL_STYLE, currentstyle & ~win32con.CS_DBLCLKS)
But it has no effect.
I tried writing a low-level hook for the mouse driver, with SetWindowsHookEx, but it doesn't work -- obviously the mouse messages are being pre-processed even before they are sent to my low-level Windows hook.
I would be very grateful for advice about how to turn off this pre-processing. I do not want to switch to RealTimeStylus -- first because it won't work on Windows XP plus SMART interactive whiteboard, second because I can't see how to use RealTimeStylus in CPython, so I would need to switch to IronPython, and then my code would no longer run on Linux/Mac.
Damon.
For raw mouse messages, you can use WM_INPUT on XP and later. Seven added some touch specific stuff: WM_GESTURE and WM_TOUCH

Categories