Sending keyboard input to a program from command-line

后端 未结 4 1317
轻奢々
轻奢々 2021-02-01 23:44

How do you send keyboard input to a program?

That is, under a Linux GUI, is there a good manual (programmable) way, or tool, of simulating keyboard input on a running pr

相关标签:
4条回答
  • 2021-02-02 00:25

    I found these two programs xmacro and xremote you may take a look, but it seems that they're not well documented.

    I also found this utility xvkbd in answer to this question SO Q&A titled: Sending keycode to Xorg + wine with bash script.

    0 讨论(0)
  • 2021-02-02 00:29

    xdotool does have a way of sending keystrokes if limited to a focused window:

    WID=`xdotool search "Mozilla Firefox" | head -1`
    xdotool windowactivate $WID
    xdotool key ctrl+l
    
    0 讨论(0)
  • 2021-02-02 00:35

    I've built a Ruby DSL around xdotool to simplify the focusing of windows and simulation of keyboard input. Here's an example, riffing on your original request:

    Mani.new(window_manager: :xmonad) do
      window :hello, launch: 'urxvt' do
        run 'echo "hello\n"'
      end
    
      window :firefox, launch: 'firefox', delay: 1.5 do
        type '{{ctrl+t}}'
      end
    end
    
    0 讨论(0)
  • 2021-02-02 00:38

    It's an old topic, but one still may be looking for this, someone mentioned here solution where window must be activated when using xdotool. However you can specify window and even use xdotool to find it. Here is example I tried to accomplish, change it as you need.

    xdotool key --window $(xdotool search --name "Spotify (Premium |Free )?- Linux Preview" | head -n1) ctrl+KP_Down
    
    0 讨论(0)
提交回复
热议问题