Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] Automation - Sending events to games
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Gamers & Players
View previous topic :: View next topic  
Author Message
benny.balrog
n00b
n00b


Joined: 14 Nov 2022
Posts: 2

PostPosted: Mon Nov 14, 2022 4:24 pm    Post subject: [SOLVED] Automation - Sending events to games Reply with quote

So, I'd like to write some scripts to complete some very tedious tasks in some very dumb games. For some of them, xdotool is more than enough but several games (or even some apps, like PyCharm) do not respond to xdotool events. I have tried to write my own tool, but so far without success.

So far I have tried the following python modules:
- mouse and keyboard
- xdo
- evdev

I got them to work for normal applications, but those who do not respond to xdotool, do not respond to these libraries either.

I'd prefer to stay in python but I could change to other language if there is something easier for this purpose.

Any suggestions?


Last edited by benny.balrog on Fri Nov 18, 2022 7:34 pm; edited 1 time in total
Back to top
View user's profile Send private message
psycho
Guru
Guru


Joined: 22 Jun 2007
Posts: 534
Location: New Zealand

PostPosted: Thu Nov 17, 2022 1:14 am    Post subject: Reply with quote

Hi Benny.

Are you using xdotool to input to your game's window specifically, or just to the active window? Some applications reject input when it's being directed to their windows specifically (in that special way that can still send them input while they don't have the focus); but they should still accept it in the normal way while they have the focus (otherwise presumably they wouldn't be accepting any input at all). This being the case, if your scripts are directing input specifically to those games etc., it might work to change them so that they send it to whichever window happens to be active (and, of course, kick them off by using something like wmctrl to bring your desired program to the foreground so that your xdotool events are sent to it). Obviously it's safer to send events to specific windows as there's some potential for disastrous mayhem when you're scripting input events into whatever window happens to have the focus... but if your desktop has focus stealing prevention and depending on what input you're sending, it might meet your needs to do it that way.
Back to top
View user's profile Send private message
benny.balrog
n00b
n00b


Joined: 14 Nov 2022
Posts: 2

PostPosted: Fri Nov 18, 2022 7:34 pm    Post subject: Reply with quote

Thank you for the suggestion psycho.

I always send to the active window (e.g. sleep 2; xdotool blabla). I think that this is a more fundamental problem. Some of the libraries I tried using (e.g. mouse and keyboard from Python3) explicitly mention that some app/games hook up the input events directly and that they cannot send events to these apps/games.

I solved the problem by using libevemu which injects events directly into /dev/input/event*. It is less secure because it requires root permission or access to the "input" group, but it works. There is a Python3 wrapper but it is not documented and I honestly didn't get it even when I was reading its source code. Solution? I wrote my own Python3 interface to the functions I need from this library (which are not many). It is working like a charm.

Thank you for the feedback though!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gamers & Players All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum