Я пытаюсь отправить короткую последовательность нажатий клавиш в 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 конфликтует с взаимодействием с пользователем во время выполнения моего скрипта. Любая помощь ценится! :)
Многие программы не допускают нажатий клавиш, когда у них нет клавиатуры, что, безусловно, имеет смысл.
Но вам не нужно использовать «windowactivate», «windowfocus» работает и не выводит окно на передний план и т. Д. введите команду в одну строку, используя команду 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.