Advertisement
lilo_booter

Cocky Rebellion

May 18th, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.20 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # Copyright (C) 2018 Charles Yates
  4. # Released under the LGPL
  5. # Faleena Hopkins can go spin
  6.  
  7. # COCKY LIBRARY
  8.  
  9. cocky() {
  10.     # Handle arguments
  11.     local js=${1:-/dev/input/js0}
  12.     local running="/tmp/cocky-$( basename $js )"
  13.  
  14.     rm -f "$running"
  15.  
  16.     trap "cocky_trap $running" SIGINT SIGTERM EXIT SIGHUP SIGQUIT SIGPIPE
  17.  
  18.     cocky_read |
  19.     while [[ ! -f "$running" ]] ; do
  20.         cocky_process
  21.     done
  22. }
  23.  
  24. cocky_read() {
  25.     exec jstest --event "$js"
  26. }
  27.  
  28. cocky_trap() {
  29.     touch "$1"
  30. }
  31.  
  32. cocky_process() {
  33.     local type time number value junk
  34.     read -r -t 0.01
  35.     if [[ "$REPLY" =~ ^Event:.type.[12]+,.*$ ]] ; then
  36.         IFS=' ,' read junk junk type junk time junk number junk value <<< "$REPLY"
  37.         case "$type" in
  38.         1) cocky_button "$number" "$value" "$time" ;;
  39.         2) cocky_axis "$number" "$value" "$time" ;;
  40.         esac
  41.     elif [[ "$REPLY" == "" ]] ; then
  42.         cocky_event
  43.     fi
  44. }
  45.  
  46. # Stubs in case application doesn't define them
  47. cocky_button() { return ; }
  48. cocky_axis() { return ; }
  49. cocky_event() { return ; }
  50.  
  51. #!/usr/bin/env bash
  52.  
  53. # REBELLION
  54.  
  55. # Copyright (C) 2018 Charles Yates
  56. # Released under the LGPL
  57.  
  58. #DIR=$( dirname "${BASH_SOURCE[0]}" )
  59. #source "$DIR/cocky.sh"
  60.  
  61. speed_x=0
  62. speed_y=0
  63.  
  64. cocky_button() {
  65.     local mouse key method
  66.  
  67.     case "$1" in
  68.     0) mouse=1 ;; # Left
  69.     1) mouse=3 ;; # Middle
  70.     2) mouse=1 ;; # Left
  71.     3) mouse=2 ;; # Right
  72.     4) key=Page_Up ;;
  73.     5) key=Page_Down ;;
  74.     *) return ;;
  75.     esac
  76.  
  77.     if [[ "$mouse" != "" ]] ; then
  78.         case "$2" in
  79.         0) method=mouseup ;;
  80.         1) method=mousedown ;;
  81.         *) return ;;
  82.         esac
  83.         xte "$method $mouse"
  84.     elif [[ "$key" != "" ]] ; then
  85.         case "$2" in
  86.         0) method=keyup ;;
  87.         1) method=keydown ;;
  88.         *) return ;;
  89.         esac
  90.         xte "$method $key"
  91.     fi
  92. }
  93.  
  94. cocky_axis() {
  95.     case "$1" in
  96.     0) let "speed_x=$2/2048" ;;
  97.     1) let "speed_y=$2/2048" ;;
  98.     3) let "speed_x=$2/8192" ;;
  99.     4) let "speed_y=$2/8192" ;;
  100.     6) let "speed_x=2*$2/32767" ;;
  101.     7) let "speed_y=2*$2/32767" ;;
  102.     esac
  103.     (( speed_x > -2 && speed_x < 2 )) && speed_x=0
  104.     (( speed_y > -2 && speed_y < 2 )) && speed_y=0
  105.     xte "mousermove $speed_x $speed_y"
  106. }
  107.  
  108. cocky_event() {
  109.     if (( "$speed_x" != 0 || "$speed_y" != 0 )) ; then
  110.         xte "mousermove $speed_x $speed_y"
  111.     fi
  112. }
  113.  
  114. [[ "$_" != "$0" ]] && cocky "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement