How to send keystrokes to unfocused window?

Questions about Wine on Linux
Locked
hajonnes
Level 2
Level 2
Posts: 10
Joined: Sat Oct 16, 2021 6:23 pm

How to send keystrokes to unfocused window?

Post by hajonnes »

Hi,
I would like to send F6 to the windows application Balabolka when pressing ctrl+F6 on my keyboard.

I was thinking of using xbindkeys and xdotools. As a start I'm trying to get Balabolka to react to xdotools just to see if it works. But I have not been able to make it work.

❯ xdotool search --name Balabolka
81788992
81788931
81788934
❯ xdotool search --name Balabolka key F6

First, out of curisity, does anyone know why I get so many windows id's for the application?
Secondly, the command to send F6 does not generate any errors but nothing happeneds.
I have also tried.

❯ xdotool search --class balabolka windowfocus key F6
X Error of failed request: BadMatch (invalid parameter attributes)
Major opcode of failed request: 42 (X_SetInputFocus)
Serial number of failed request: 2110
Current serial number in output stream: 2111


I have installed autohotkey in my wine prefix but I do not really know how to use it with this.

Well any hints of solutions is appreciated.

@ documentation maintainers, It would be nice if this is a thing that is mentioned in the wine wiki.

Operating System: Manjaro Linux
KDE Plasma Version: 5.22.5
KDE Frameworks Version: 5.86.0
Qt Version: 5.15.2
Kernel Version: 5.13.19-2-MANJARO (64-bit)
Graphics Platform: X11
Processors: 4 × Intel® Core™ i5-6600K CPU @ 3.50GHz
Memory: 31,3 GiB of RAM
Graphics Processor: NVIDIA GeForce GTX 960/PCIe/SSE2
With wine 6.16
and xdotool version 3.20210903.1
User avatar
Bob Wya
Level 12
Level 12
Posts: 3068
Joined: Sat Oct 16, 2010 7:40 pm

Re: How to send keystrokes to unfocused window?

Post by Bob Wya »

hajonnes wrote: Sun Oct 17, 2021 1:08 pm ...
I have installed autohotkey in my wine prefix but I do not really know how to use it with this.
...
AutoIt or AutoHotKey are the way to go, for your stated use case / goal.

winetricks uses AHK internally for automating Windows control actions - so you could take a look at the monolithic winetricks script.

I've personally used AutoIt many years ago - for Windows scripting purposes - it's very easy to pick, and has excellent documentation. E.g. take a look at: AutoIt Tutorial - Notepad. This tutorial appears to cover most of the information you'd need - for your personal use case of this tool.

Bob
hajonnes
Level 2
Level 2
Posts: 10
Joined: Sat Oct 16, 2021 6:23 pm

Re: How to send keystrokes to unfocused window?

Post by hajonnes »

Is this not a multiple stage problem?
First, I need to intercept the keystroke (e.g. ctrl+F6) so it does not get sent to the focused window.
Second, I need the keystroke to trigger a sending of keystroke to the unfocused wine window.
Third, unfocused window needs to accept the keystroke
Forth, the program needs to get the keystroke.

Perhaps I have missunderstood how this all works, since you have got it to work how did you solve it?

About the third stage: As my example shows, some windows does not accept keystrokes generated with xdotools.
Locked