bfgminer 没有捕获 xdotool

bfgminer 没有捕获 xdotool

我正在尝试向 bfgminer 发送一小段击键序列,但不将其窗口置于焦点,它在 gnome 终端中运行。

#! /bin/bash
xdotool key --window 25165831 p
sleep 1
xdotool key --window 25165831 s
sleep 1
xdotool key --window 25165831 0

什么都没发生。尽管当我运行以下脚本时它可以工作。

#! /bin/bash
xdotool windowactivate 25165831
sleep 1
xdotool key p
sleep 1
xdotool key s
sleep 1
xdotool key 0

我已经研究过了,expect但它又大又复杂,我只是在寻找一个简短而简单的解决方案。虽然从我读到的内容来看,这似乎expect可以完成工作。如果 xdotool 在执行我的脚本时与用户交互发生冲突,也许使用 expect 会更好。任何帮助都非常感谢!:)

答案1

当没有键盘焦点时,许多程序不会接受按键 - 这当然是有道理的。

但是您不需要使用“windowactivate”,“windowfocus”可以工作,并且不会将窗口置于前面等:
xdotool windowfocus 8392809 key p

sleep另外,你可以使用以下命令将命令简化为一行xdotool

xdotool key p sleep 0.5 key s

或使用--delay命令的选项key


背景:您尝试的命令看起来非常相似,但存在技术差异,解释如下man xdotool

SENDEVENT NOTES
    If you are trying to send key input to a specific window, and it does not appear to be working, then it's
    likely your application is ignoring the events xdotool is generating. This is fairly common.

    Sending keystrokes to a specific window uses a different API than simply typing to the active window. If you
    specify 'xdotool type --window 12345 hello' xdotool will generate key events and send them directly to window
    12345.  However, X11 servers will set a special flag on all events generated in this way (see
    XEvent.xany.send_event in X11's manual). Many programs observe this flag and reject these events.

    It is important to note that for key and mouse events, we only use XSendEvent when a specific window is
    targeted. Otherwise, we use XTEST.

    Some programs can be configured to accept events even if they are generated by xdotool. Seek the documentation
    of your application for help.

    Specific application notes (from the author's testing): * Firefox 3 seems to ignore all input when it does not
    have focus.  * xterm can be configured while running with ctrl+leftclick, 'Allow SendEvents' * gnome-terminal
    appears to accept generated input by default.

相关内容