Improve key spam in lxdotool

Hello Manjaro community,

A few weeks ago I created a script that has the function of repeatedly sending F12 to a game of mine, even if it’s in the background, let’s call it “GameWar”

The script was assembled as follows

#!/bin/bash
while true;
do sleep $(shuf -i2-5 -n1);
xdotool key --window $(xdotool search --name 'GameWar') F12;
done

The function of sending F12 in an interval between 2s and 5s is working, however, the problems I am facing are the following;

  1. I would like F12 to be sent to the game, even if it is minimized or in the background, the code above sends F12 , but only if the game is focused/foreground.

What I would like to implement is the following;

  1. I would like F12 not to be sent when I am pressing any other key or mouse click, is it possible to implement this?

Nope.

  • If it’s a game with a GUI: no.
  • If it’s a text-only game, you can tmux it

:sob:

I understand,
But can I improve the code above so that the “F12” key is only sent if no other keyboard keys are being pressed?

  • In bash? Not that I can see as you don’t have access to the system-wide keyboard buffer.
  • In C? Yes for sure if you’d go through the trouble of writing a kernel module… :scream: