Controlling mouse movement with python inside a game

Controlling mouse movement with python inside a game



I want to learn some reinforcement-learning concepts by letting my agent play a video game. In order to do so, I would like to control the mouse movement inside the game.



I've been fiddling with win32api, using win32api.SetCursorPos((x,y))to move the mouse. While this works perfectly on my desktop, I can't find a way to translate the movement inside the game.


win32api.SetCursorPos((x,y))



I have also tried using pyautogui with no luck either.



Any suggestions on how to solve this?




1 Answer
1


from pynput.mouse import Controller, Button


def clickAt(Mouse, x, y):
Mouse.position = (x, y)
Mouse.press(Button.right)
Mouse.release(Button.right)


Mouse = Controller()
clickAt(Mouse,100,100)



This is how you do it with pynput





same problem as with the other modules I've tried. It works on desktop but not ingame :S
– AaronDT
Aug 29 at 21:33





Put the game in windowed mode rather than full screen.
– vividpk21
Aug 29 at 21:34





I did, but once I click on the game window the mouse "disappears". It recognizes mouse clicks but not the movement
– AaronDT
Aug 29 at 21:35






That's a different question all together, you need to figure out what library/how the game itself is handling input and then find a way to simulate so that it behaves as you want.
– vividpk21
Aug 30 at 4:25



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế