3

XDOToolo を使用して単純な無限クリック スクリプトを別のスクリプトと統合して、キーボード入力を検出しようとしています。キーが押されたときに実行中のクリックスクリプトを終了しますが、それらを一致させる方法が不明です。

このスクリプトは、XDOTool によって決定された画面のカーソル ポイント XXX、YYY を無限に繰り返しクリックして実行されます。

 #!/bin/bash
 while true [ 1 ]; do
 xdotool mousemove XXX YYY click 1 &
 sleep 1.5
 done

次に、次のようなものを使用したいと思います。

#!/bin/bash
if [ -t 0 ]; then stty -echo -icanon -icrnl time 0 min 0; fi
count=0
keypress=''
while [ "x$keypress" = "x" ]; do
let count+=1
echo -ne $count'\r'
keypress="`cat -v`"
done
if [ -t 0 ]; then stty sane; fi
echo "You pressed '$keypress' after $count loop iterations"
echo "Thanks for using this script."
exit 0

私は私が取る方法を理解していません:

 xdotool mousemove XXX YYY click 1 &
 sleep 1.5

そして、上記のスクリプトのどこに置くべきか、BASH の混乱と MAN BASH は役に立たないので、支援できる人なら誰でも感謝します。ありがとう

4

1 に答える 1

6

Improved (and commented) script:

#!/bin/bash

x_pos="0"   # Position of the mouse pointer in X.
y_pos="0"   # Position of the mouse pointer in Y.
delay="1.5" # Delay between clicks.

# Exit if not running from a terminal.
test -t 0 || exit 1

# When killed, run stty sane.
trap 'stty sane; exit' SIGINT SIGKILL SIGTERM

# On exit, kill this script and it's child processes (the loop).
trap 'kill 0' EXIT

# Do not show ^Key when pressing Ctrl+Key.
stty -echo -icanon -icrnl time 0 min 0

# Infinite loop...
while true; do
    xdotool mousemove "$x_pos" "$y_pos" click 1 &
    sleep "$delay"
done & # Note the &: We are running the loop in the background to let read to act.

# Pause until reads a character.
read -n 1

# Exit.
exit 0
于 2015-04-19T13:03:14.303 に答える