Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # Copyright (C) 2018 Charles Yates
- # Released under the LGPL
- # Faleena Hopkins can go spin
- # COCKY LIBRARY
- cocky() {
- # Handle arguments
- local js=${1:-/dev/input/js0}
- local running="/tmp/cocky-$( basename $js )"
- rm -f "$running"
- trap "cocky_trap $running" SIGINT SIGTERM EXIT SIGHUP SIGQUIT SIGPIPE
- cocky_read |
- while [[ ! -f "$running" ]] ; do
- cocky_process
- done
- }
- cocky_read() {
- exec jstest --event "$js"
- }
- cocky_trap() {
- touch "$1"
- }
- cocky_process() {
- local type time number value junk
- read -r -t 0.01
- if [[ "$REPLY" =~ ^Event:.type.[12]+,.*$ ]] ; then
- IFS=' ,' read junk junk type junk time junk number junk value <<< "$REPLY"
- case "$type" in
- 1) cocky_button "$number" "$value" "$time" ;;
- 2) cocky_axis "$number" "$value" "$time" ;;
- esac
- elif [[ "$REPLY" == "" ]] ; then
- cocky_event
- fi
- }
- # Stubs in case application doesn't define them
- cocky_button() { return ; }
- cocky_axis() { return ; }
- cocky_event() { return ; }
- #!/usr/bin/env bash
- # REBELLION
- # Copyright (C) 2018 Charles Yates
- # Released under the LGPL
- #DIR=$( dirname "${BASH_SOURCE[0]}" )
- #source "$DIR/cocky.sh"
- speed_x=0
- speed_y=0
- cocky_button() {
- local mouse key method
- case "$1" in
- 0) mouse=1 ;; # Left
- 1) mouse=3 ;; # Middle
- 2) mouse=1 ;; # Left
- 3) mouse=2 ;; # Right
- 4) key=Page_Up ;;
- 5) key=Page_Down ;;
- *) return ;;
- esac
- if [[ "$mouse" != "" ]] ; then
- case "$2" in
- 0) method=mouseup ;;
- 1) method=mousedown ;;
- *) return ;;
- esac
- xte "$method $mouse"
- elif [[ "$key" != "" ]] ; then
- case "$2" in
- 0) method=keyup ;;
- 1) method=keydown ;;
- *) return ;;
- esac
- xte "$method $key"
- fi
- }
- cocky_axis() {
- case "$1" in
- 0) let "speed_x=$2/2048" ;;
- 1) let "speed_y=$2/2048" ;;
- 3) let "speed_x=$2/8192" ;;
- 4) let "speed_y=$2/8192" ;;
- 6) let "speed_x=2*$2/32767" ;;
- 7) let "speed_y=2*$2/32767" ;;
- esac
- (( speed_x > -2 && speed_x < 2 )) && speed_x=0
- (( speed_y > -2 && speed_y < 2 )) && speed_y=0
- xte "mousermove $speed_x $speed_y"
- }
- cocky_event() {
- if (( "$speed_x" != 0 || "$speed_y" != 0 )) ; then
- xte "mousermove $speed_x $speed_y"
- fi
- }
- [[ "$_" != "$0" ]] && cocky "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement