Let's say there is a program (like OBS, Chrome, or Discord) that accepts hotkeys (to open, save, print, etc) how can I forward a global hotkey like those configured in i3 to a program that only local accepts events targeted to the window.

For example, let's say I want to target a running version of Chrome for Printing (Ctrl+P). How can I set up a hotkey such that Chrome will open up the printing dialog (CTRL+P) if it's not in focus?

1 Answer 1


You can do this by,

  1. Finding both,
    • Your current active window. (src)
    • The target window. (dst).
  2. Scripting,
    1. bounce to the dst
    2. a submission of the key
    3. a bounce back to the src

To find the window that's open you can use xdotool,

src=$(xdotool getwindowfocus)
dst=$(xdotool search --onlyvisible --class "Chromium")

And then to send it the proper key you can use,

export key="Ctrl+P"
xdotool windowfocus --sync "$dst" key "$key" windowfocus --sync "$src"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .