zclick: cleanup code
This commit is contained in:
parent
3c26c11981
commit
cf9451bb1f
1 changed files with 46 additions and 46 deletions
|
|
@ -1,15 +1,19 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
usage ()
|
fname=$(basename "$0")
|
||||||
|
usage()
|
||||||
{
|
{
|
||||||
echo "zclick [options]"
|
echo "$fname [options] [clickID]
|
||||||
echo ""
|
Automatic clicker. Click ID is: 1=left , 2=middle , 3=right
|
||||||
echo "Options:"
|
To run the clicker, you need to start the daemon and then run the commands
|
||||||
echo " -h Display this help"
|
|
||||||
echo " -d Run daemon"
|
[Daemon Options]
|
||||||
echo " -c <id> Click ID: 1:left 2:middle 3:right."
|
-d Run daemon
|
||||||
echo " -i <ms> Interval between clicks in ms, 0 for no clicking. Default 20."
|
-b <ms> Time per block of operation in ms. Default 100"
|
||||||
echo " -t Toggle clicking. Sets interval to 0 if current value was != 0"
|
[Client options]
|
||||||
|
-h Display this help
|
||||||
|
-i <ms> Interval between clicks in ms, 0 for no clicking. Default 20
|
||||||
|
-t Toggle clicking. Sets interval to 0 if current value was != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
error () {
|
error () {
|
||||||
|
|
@ -19,6 +23,7 @@ error () {
|
||||||
arg_i=20
|
arg_i=20
|
||||||
block_time=100
|
block_time=100
|
||||||
|
|
||||||
|
|
||||||
if [ -z "$FOLDER" ]
|
if [ -z "$FOLDER" ]
|
||||||
then
|
then
|
||||||
if [ -n "$XDG_DATA_HOME" ]
|
if [ -n "$XDG_DATA_HOME" ]
|
||||||
|
|
@ -29,49 +34,29 @@ then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while getopts ":hc:i:dt" opt;
|
while getopts ":hi:b:dt" opt;
|
||||||
do
|
do
|
||||||
case $opt in
|
case $opt in
|
||||||
h)
|
h)
|
||||||
usage
|
usage
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
c)
|
|
||||||
if ! echo "$OPTARG" | grep -Eq '^[0-9]+$'
|
|
||||||
then
|
|
||||||
error "c argument has to be an integer"
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
if [ -z "$OPTARG" ]
|
|
||||||
then
|
|
||||||
error "c needs an argument"
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
if [ "$OPTARG" -lt 1 ]
|
|
||||||
then
|
|
||||||
error "c argument has to be greater than 0"
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
arg_c=$OPTARG
|
|
||||||
;;
|
|
||||||
i)
|
i)
|
||||||
if ! echo "$OPTARG" | grep -Eq '^[0-9]+$'
|
if ! [ "$OPTARG" -ge 0 ] 2>/dev/null
|
||||||
then
|
then
|
||||||
error "i argument has to be an integer"
|
error "i argument has to be positive"
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
if [ -z "$OPTARG" ]
|
|
||||||
then
|
|
||||||
error "i needs an argument"
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
if [ "$OPTARG" -lt 1 ]
|
|
||||||
then
|
|
||||||
error "i argument has to be greater than 0"
|
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
arg_i=$OPTARG
|
arg_i=$OPTARG
|
||||||
;;
|
;;
|
||||||
|
b)
|
||||||
|
if ! [ "$OPTARG" -ge 1 ] 2>/dev/null
|
||||||
|
then
|
||||||
|
error "b argument has to be strictly positive"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
block_time=$OPTARG
|
||||||
|
;;
|
||||||
d)
|
d)
|
||||||
opt_d=y
|
opt_d=y
|
||||||
;;
|
;;
|
||||||
|
|
@ -86,12 +71,23 @@ do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
|
if [ -n "$1" ] && ! [ "$1" -gt 0 ] 2>/dev/null
|
||||||
|
then
|
||||||
|
error "Click ID has to be a strictly positive integer"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
cid=$1
|
||||||
|
|
||||||
|
|
||||||
mkdir -p "$FOLDER"
|
mkdir -p "$FOLDER"
|
||||||
|
|
||||||
if [ -n "$opt_d" ]
|
if [ -n "$opt_d" ]
|
||||||
then
|
then
|
||||||
## DAEMON
|
## DAEMON
|
||||||
# reset status of all clicks
|
# reset status of all clicks
|
||||||
|
stime=$(echo "scale=2;$block_time/1000.0" | bc)
|
||||||
for I in "$FOLDER"/*
|
for I in "$FOLDER"/*
|
||||||
do
|
do
|
||||||
echo "0" > "$I"
|
echo "0" > "$I"
|
||||||
|
|
@ -99,21 +95,25 @@ then
|
||||||
# DAEMON
|
# DAEMON
|
||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
|
sleep $stime &
|
||||||
for I in "$FOLDER"/*
|
for I in "$FOLDER"/*
|
||||||
do
|
do
|
||||||
interval=$(cat "$I")
|
interval=$(cat "$I")
|
||||||
click_id=$(echo "$I" | rev | cut -d'/' -f1 | rev)
|
click_id=$(echo "$I" | rev | cut -d'/' -f1 | rev)
|
||||||
if [ "$interval" != "0" ]
|
if [ "$interval" != "0" ]
|
||||||
then
|
then
|
||||||
xdotool click --repeat "$(echo "$block_time / $arg_i" | bc)" --delay "$interval" "$click_id"
|
N=$(($block_time / $interval))
|
||||||
|
[ "$N" -lt 1 ] && N=1
|
||||||
|
xdotool click --repeat $N --delay $interval $click_id &
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
wait $(jobs -p)
|
||||||
done
|
done
|
||||||
|
|
||||||
else
|
else
|
||||||
## CONTROL
|
## CONTROL
|
||||||
|
|
||||||
if [ -z "$arg_c" ]
|
if [ -z "$cid" ]
|
||||||
then
|
then
|
||||||
usage
|
usage
|
||||||
exit
|
exit
|
||||||
|
|
@ -122,15 +122,15 @@ else
|
||||||
if [ -n "$opt_t" ]
|
if [ -n "$opt_t" ]
|
||||||
then
|
then
|
||||||
#toggle
|
#toggle
|
||||||
if [ "$(cat "$FOLDER/$arg_c")" != "0" ] ; then
|
if [ "$(cat "$FOLDER/$cid")" != "0" ] ; then
|
||||||
echo 0 > "$FOLDER/$arg_c"
|
echo 0 > "$FOLDER/$cid"
|
||||||
else
|
else
|
||||||
echo "$arg_i" > "$FOLDER/$arg_c"
|
echo "$arg_i" > "$FOLDER/$cid"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
#set
|
#set
|
||||||
echo "$arg_i" > "$FOLDER/$arg_c"
|
echo "$arg_i" > "$FOLDER/$cid"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue