sending one key stroke to two windows (Ubuntu)

5,738

Solution 1

I don't see an easy way to do this while inside one of your debugging windows, but you could use a third windows running a script that wrapped around xvkbd. It's in the ubuntu repository (might be in universe). The script could read your keyboard input and then call xvkbd twice, sending the keystrokes to both windows. Normally a graphical program, using

xvkbd -window xterm2 -text $foo

sends key events to specific windows, but doesn't invoke a UI. You also might find that wmctrl helps identify windows & stuff. A simplistic script might be:

#!/bin/bash

while [ 1 ]; do
    wmctrl -i -a 0x02200003   #forcibly set focus in window running script
    read keys
    xvkbd -window 0x2202ea4 -text "$keys\r"
    xvkbd -window 0x2200084 -text "$keys\r"
done

Solution 2

The Terminator application (not to be confused by a Java application with the same name) provides exactly the functionality you need. You can install it from Ubuntu's repositories with apt-get install terminator.

Here's how it works:

  • run Terminator
  • open multiple sessions in tabs or frames
  • click the button at the top left corner of a frame
  • select the "New group..." menu item
  • type a name for the group
  • in each session you want to send keystrokes to, select that group from the menu
  • you can use the "Broadcast group" and "Broadcast off" menu items to toggle broadcasting keystrokes.

There are also keyboard shortcuts for this.

Solution 3

You'd not be able to do that in GNOME Terminal, IIRC.

If you'd like to try Konsole, there's a Send Input to All Sessions option in Konsole 3, which becomes Copy Input to... in Konsole 4.

Solution 4

Besides clusterssh, which is basically designed to do this but insists on spawning its own terminals, you can use xlax, which is a generic solution to distribute/send keystrokes to multiple X11 windows. It’s not packaged yet, but I will do that, as I needed “something like clusterssh, just for virt-manager” right now, and found this to be my tool of choice.

Share:
5,738

Related videos on Youtube

Admin
Author by

Admin

Updated on September 17, 2022

Comments

  • Admin
    Admin over 1 year

    I'm running Ubuntu Linux. I have two open Terminal windows running side by side. I'm looking to be able to hit the enter key once, and have that key stroke sent to both windows.

    (What I'm doing is stepping through some code on two different systems using a debugger, and I don't want to have to keep switching back and forth between the windows as I step through the code.)

    Thanks!

  • John T
    John T over 14 years
    1 = 1 is not necessary, while [ 1 ] does the same thing :P
  • DaveParillo
    DaveParillo over 14 years
    I tested ny example script in gnome-terminal. worked ok.
  • 0x44
    0x44 over 14 years
    With the built-in fuctions of GNOME Terminal, I mean. :-)