0

I'm trying to send a keyboard key sequence to a client from the terminal using awesome-client, with the fake_input function (https://awesomewm.org/doc/api/libraries/root.html#fake_input), I used the send_string_to_client snippet.

However, this doesn't work. The specified client gets the focus but the keys are sent to the terminal from where I called the awesome-client. I also tried after adding a awful.keygrabber.stop() and a awesome.sync() to let awesome know about the client focus change, but that doesn't do the trick...

Any idea ?

  • Does "wait for the focus change to be done" count as an answer? You could connect to the client's `focus` signal and send the input only then. – Uli Schlachter Sep 23 '20 at 14:56
  • Also, I guess the problem is that the client that you want to send input to has `WM_TAKE_FOCUS` in its `WM_PROTOCOLS` property (you can check this with `xprop`). This means (I am slightly simplifying here) that the WM may not focus the window directly, but instead sends a message "I want to give you input focus". The program in question now takes a bit to handle this message. You are sending the input before the app is done with the focus change. – Uli Schlachter Sep 23 '20 at 14:58
  • Well I tried with the connection to the signal, but unfortunately the input is still sent to the calling terminal. Here is the code, where c is my client : ´local old_c = client.focus´ c:connect_signal("focus", function(c) local naughty = require"naughty" naughty.notification { urgency = "critical", title = "new_focus", message = c.class } local input = "a" root.fake_input("key_press", input) root.fake_input("key_release", input) end) client.focus = c – Paul Bonnot Sep 24 '20 at 15:45
  • So I know that the client has focus from the notification in the callback, but the fake input is still sent to the calling terminal. And I also added a 1 second sleep in the callback to make sure the client had the time to wake up, but it still doesn't work... – Paul Bonnot Sep 24 '20 at 15:57
  • This time I actually tried it. Did not work for me at first as well when doing `awesome-client 'do_it()'` (where `do_it` calls `send_string_to_client` as in the example). Then I switched to `awesome-client 'require("gears.timer").start_new(1, do_it)'` and that worked, but I have no idea why. Seems like the terminal does not accept input while a program is running? Or perhaps things go wrong because the enter key is still pressed when this runs? – Uli Schlachter Sep 25 '20 at 16:18

0 Answers0