How to control a process under Wine?

Questions about Wine on Linux
Locked
akamaus
Level 1
Level 1
Posts: 9
Joined: Tue Aug 28, 2012 1:46 am

How to control a process under Wine?

Post by akamaus »

Greetings.
I'm going to automate a particular piece of software. In order to do that, I need to be able to read the process memory and send keyboard and mouse messages to it.

It's quite straightforward under Windows. But can it be done for a process running under Wine with a controlling script running in a Linux environment? I guess, there are different approaches. I would be glad to hear any ideas. References for relevant reading are welcome too :)
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: How to control a process under Wine?

Post by vitamin »

akamaus wrote:It's quite straightforward under Windows. But can it be done for a process running under Wine with a controlling script running in a Linux environment?
It is the same on Wine. But no, you can't run script in Linux. It will have to be a Windows program running inside Wine.
akamaus
Level 1
Level 1
Posts: 9
Joined: Tue Aug 28, 2012 1:46 am

Re: How to control a process under Wine?

Post by akamaus »

vitamin wrote: It is the same on Wine. But no, you can't run script in Linux. It will have to be a Windows program running inside Wine.
It's a bad news. I'm far more familiar with a unix environment and toolchain. And I'm afraid I wasn't clear enough. For example memory of a process running in Wine can surely be read from /proc. Do you mean there is just no easier way?
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: How to control a process under Wine?

Post by vitamin »

akamaus wrote:For example memory of a process running in Wine can surely be read from /proc.
Yes of course. But what good will it do it you don't know what's there?

Wine only creates X windows for top level windows, not each individual control. So you can't send mouse/keyboard events that way. Or rather it will be really difficult. This is as far as controlling goes.
akamaus
Level 1
Level 1
Posts: 9
Joined: Tue Aug 28, 2012 1:46 am

Re: How to control a process under Wine?

Post by akamaus »

vitamin wrote:
akamaus wrote:For example memory of a process running in Wine can surely be read from /proc.
Yes of course. But what good will it do it you don't know what's there?
Well, it's just a matter of doing some reverse engineering. What puzzles me is memory layout of wine processes. Can I find a good description somethere?
vitamin wrote: Wine only creates X windows for top level windows, not each individual control. So you can't send mouse/keyboard events that way. Or rather it will be really difficult. This is as far as controlling goes.
I'm actually speaking about a game. so it's not a problem. Till now I've been experimenting with X Test extension, it works, but I'd like to find some less intrusive way. XSendEvent seems to be ideal, but looks like Wine ignores messages sent this way. Is there a good reason for this? I suspect it's quite trivial to patch, isn't it?
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: How to control a process under Wine?

Post by vitamin »

akamaus wrote:Can I find a good description somethere?
Sure: http://source.winehq.org/git/wine.git/tree
akamaus wrote:I'm actually speaking about a game.
Which one?
akamaus wrote:XSendEvent seems to be ideal, but looks like Wine ignores messages sent this way.
It might work for keyboard but not for mouse. Wine uses XInput which provides raw device events.
akamaus
Level 1
Level 1
Posts: 9
Joined: Tue Aug 28, 2012 1:46 am

Re: How to control a process under Wine?

Post by akamaus »

vitamin wrote:
akamaus wrote:XSendEvent seems to be ideal, but looks like Wine ignores messages sent this way.
It might work for keyboard but not for mouse. Wine uses XInput which provides raw device events.
XSendEvent works (I tested with xdotool --window), but only for active windows. What's about the background ones? I found this thread: http://forum.winehq.org/viewtopic.php?f=2&t=4135

Now I probably I should reformulate my question a bit. Is there a way to post messages to input queue of a thread from the Unix side?
akamaus
Level 1
Level 1
Posts: 9
Joined: Tue Aug 28, 2012 1:46 am

Re: How to control a process under Wine?

Post by akamaus »

Answering my own question. The point of interest is function
find_hardware_message_window in server/queue.c. It's responsible for filtering keyboard messages for inactive windows.
Simon of Aragon
Level 3
Level 3
Posts: 94
Joined: Sat Sep 08, 2012 3:56 pm

Re: How to control a process under Wine?

Post by Simon of Aragon »

vitamin wrote:
akamaus wrote:It's quite straightforward under Windows. But can it be done for a process running under Wine with a controlling script running in a Linux environment?
It is the same on Wine. But no, you can't run script in Linux. It will have to be a Windows program running inside Wine.
Sorry new guy here, but it sounds like what you would need here is AutoIt or AutoHotKey for Windows running. A long side your app. Then you could run your script from there -assuming those are compatible- with whatever it is you are doing... I don't know if you want to learn a new scripting language at this point since you are more into the Linux/Unix style.
akamaus
Level 1
Level 1
Posts: 9
Joined: Tue Aug 28, 2012 1:46 am

Re: How to control a process under Wine?

Post by akamaus »

Simon of Aragon wrote: Sorry new guy here, but it sounds like what you would need here is AutoIt or AutoHotKey for Windows running. A long side your app. Then you could run your script from there -assuming those are compatible- with whatever it is you are doing... I don't know if you want to learn a new scripting language at this point since you are more into the Linux/Unix style.
My idea was to rule the process running under wine directly from unixland. That's why I tried to avoid solutions involving launching a separate win32 process. After some research I finally found a way, you just have to patch wineserver a bit to make it pass messages to non-focused windows through. So the problem is solved. Still, thanks for advices, I'll definitely look at AutoIt in the future.
User avatar
Bob Wya
Level 12
Level 12
Posts: 3068
Joined: Sat Oct 16, 2010 7:40 pm

Re: How to control a process under Wine?

Post by Bob Wya »

akamaus wrote: My idea was to rule the process running under wine directly from unixland. That's why I tried to avoid solutions involving launching a separate win32 process. After some research I finally found a way, you just have to patch wineserver a bit to make it pass messages to non-focused windows through. So the problem is solved. Still, thanks for advices, I'll definitely look at AutoIt in the future.
I'll second that. AutoIt is a very polished Win project. The documentation is second to none. I've used it extensively to automate Windows installers. You can write full GUI apps with it - but it starts to get a bit creaky - compared to say Qt.

Bob
Simon of Aragon
Level 3
Level 3
Posts: 94
Joined: Sat Sep 08, 2012 3:56 pm

Re: How to control a process under Wine?

Post by Simon of Aragon »

I am not entirely sure how this will effect wine, but it turns out there is a Linux version of AHK (AutoHotKey) http://www.ironahk.net/ IronHotKey would run in the native Linux env, but I don't know if it will effect apps running under Wine.

I used AutoIt3 and bounced a few tests off of it. I was able to send simple instructions to a program running in Wine as long as they shared the same default environment. However I could not send the commands to the window running in background or minimized. Maybe I am just not very good at coding it.

Well just wanted to keep you updated on your options. ;D
Locked