#!/usr/bin/perl use lib '/home/pdc/sg'; use cgi_util; use POSIX; no warnings 'deprecated'; $ENV{PATH}.=':/usr/local/bin' ; $ENV{PATH}.=':/root/bin' ; $ENV{PATH}.=':/usr/local/bin' if $ENV{PATH}!~m%/usr/local/bin%; $ENV{PATH}.=':/root/bin' if $ENV{PATH}!~m%/root/bin%; $ENV{zzz}=xxxxx; $PATH=$ENV{PATH}; open(O,"> /tmp/kbd") && do{ print O "PATH = $PATH\n"; for(keys %ENV) { print O "$_ = $ENV{$_}\n"; } close O; }; $env="/usr/bin/env PATH=$PATH"; if(!defined $ENV{FVWM_USERDIR}) { $ENV{FVWM_USERDIR}='/root/.fvwm'; } my $hid=shift @ARGV; $hid="/dev/uhid0" unless defined $hid; my $plato=0x20; my $speed=1/150; my $accel=80; # 100 fps? ########## my ($dx,$dy); # hi-res my $skip=0; # repeat my $accel_c=0; open HID,"<",$hid; $prev=''; $|=1; $s=''; $ENV{yyy}=xxxxx; if (open($XTE,"|$env xte")) { select $XTE; $|=1; select *STDOUT; } else { print STDERR "Cant connect xte, using xdotool\n"; $XTE=undef }; sub apos($$){ # 00-80, 80-ff; \$delta my $a=hex shift; my $delta=shift; if ($a==0x80 || $a==0x7f) { # $accel_c=0; return 0 ; } my $speed1=$speed; if ($a==0 || $a==0xff) { $accel_c++ }; $speed1*=2 if $accel_c>$accel; $speed1*=2 if $accel_c>$accel*2; $speed1*=2 if $accel_c>$accel*3; $speed1*=2 if $accel_c>$accel*4; $speed1*=2 if $accel_c>$accel*5; if($a>0x80) { $a-=$plato; $a=0x81 if $a<0x81; } elsif($a<0x80) { $a+=$plato; $a=0x7f if $a>0x7f; } my $d=($a-0x80)*$speed1; $$delta+=$d; if($d>0) { my $i=ceil($$delta+0.5); if ($i>0) { $$delta-=$i; return $i; } } if($d<0) { my $i=floor($$delta-0.5); if ($i<0) { $$delta-=$i; return $i; } } # if($a>0x80) { # $a-=$plato; # $a=0x81 if $a<0x81; # return ceil (($a-0x80)/$speeddiv1); # } # elsif($a<0x80) { # $a+=$plato; # $a=0x7f if $a>0x7f; # return floor (($a-0x80)/$speeddiv1); # } return 0; } sub skip($){ print " skip=$skip \n"; if($skip>0) { $skip--; return 1; # skip } $skip=shift; return 0; # pass } while($c=sysread(HID,$data,100)) { $f=undef; $xdo=undef; $xte=undef; $hex=sprinthex($data); my($LX,$LY,$RX,$RY,$BUT5,$BUT6); my($m); if($hex=~/^0000: (\S+) (\S+) \S+ (\S+) (\S+) (\S+) (\S+) \S+ $/m) { ($LX,$LY,$RX,$RY,$BUT5,$BUT6)=($1,$2,$3,$4,$5,$6); #print "($LX,$LY,$RX,$RY,$BUT5,$BUT6)\n"; if($BUT5 eq '0f' && $BUT6 =~'0[014]') { my $x=''; my $y=''; $x=apos($RX,\$dx); $y=apos($RY,\$dy); if ($x ne'' && $y ne'' && ($x!=0 || $y!=0)) { print "$c:($LX,$LY,$RX,$RY) x=$x y=$y \tc=$accel_c\r"; if(defined $XTE) { $xte="mousermove ${x} ${y}"; goto xte; }; $xdo="mousemove_relative -- ${x} ${y}"; goto xdo; } } if($hex=~/^0000: 80 80 00 80 80 0f 04 00/) { # $f="current move m-50w m-50w"; # goto fvwm; } if($hex=~/^0000: 80 80 00 80 80 00 04 00/) { # click L2+up $m=4; goto click if !skip(15); } if($hex=~/^0000: 80 80 00 80 80 04 04 00/) { # click L2+dn $m=5; goto click if !skip(15); } if($hex=~/^0000: 80 80 00 80 80 00 00 00/) { # click up $xte='key Up' if !skip(45); } if($hex=~/^0000: 80 80 00 80 80 04 00 00/) { # click dn $xte='key Down' if !skip(45); } if($hex=~/^0000: 80 80 00 80 80 06 00 00/) { # click left $xte='key Left' if !skip(45); } if($hex=~/^0000: 80 80 00 80 80 02 00 00/) { # click right $xte='key Right' if !skip(45); } } if($data ne $prev) { print $hex; $prev=$data; if($c>=8) { if($hex=~/^0000: 80 80 00 80 80 0f 00 00/) { # idle $skip=0; $accel_c=0; if($s eq 'move') { $s=''; if(defined $XTE) { $xte="mouseclick 4"; goto xte; } $xdo="click 4"; goto xdo; } } if($hex=~/^0000: .. .. 00 80 80 ([124])f 00 00/) { # click 1 2 3 $m=$1; $m=3 if $m==4; click: if(defined $XTE) { $xte="mouseclick $m"; goto xte; }; $xdo="click $m"; goto xdo; } # 0000: 7f 7f 00 80 80 8f 00 00 # 0000: 80 80 00 80 80 8f 00 00 if($hex=~/^0000: .. .. 00 80 80 8f 00 00/) { # click 4 print "Click 4\n"; system "ss-import -cur &"; } if($hex=~/^0000: 00 80 00 80 80 0f 10 00/) { $f="All (CurrentDesk FvwmButtons) RaiseLower"; goto fvwm; } if($hex=~/^0000: .. ff 00 80 80 0f 00 00/) { $f="Current Lower"; goto fvwm; } if($hex=~/^0000: .. 00 00 80 80 0f 00 00/) { $f="Current Raise"; goto fvwm; } if($hex=~/^0000: 80 80 00 80 80 0f 01 00/) { if($s ne 'move') { $f="Current Move"; $s='move'; goto fvwm; } } # if($hex=~/^0000: 80 80 00 80 80 0f 04 00/) { # L2 click # $f="current move m-50w m-50w"; # goto fvwm; # } if($hex=~/^0000: 80 00 00 80 80 0f 10 00/) { $f="cam_r1"; } if($hex=~/^0000: 80 ff 00 80 80 0f 10 00/) { $f="cam_l"; } if($hex=~/^0000: 80 80 00 80 80 0f 60 00/) { $f="GotoPage prev"; } if($hex=~/^0000: (\S+) (\S+) 00 (\S+) (\S+) 0f 20 00/) { my $x=''; my $y=''; $x=00 if $LX eq '80'; $y=00 if $LY eq '80'; $x=-1 if $LX eq '00'; $y=-1 if $LY eq '00'; $x=+1 if $LX eq 'ff'; $y=+1 if $LY eq 'ff'; print "($LX,$LY,$RX,$RY) x=$x y=$y\n"; $f="GotoPage ${x}p ${y}p" if $x ne'' && $y ne'' && ($x!=0 || $y!=0); } } ####### Keyboard Startex if($hex=~/^0000: 0[12] (\S+) (?:(\S+) )$/){ $k=$1; if($k eq "23"){$f="cam_r1"}; if($k eq "8a"){$f="cam_l"}; if($k eq "24"){$f="Current Lower"}; if($k eq "25"){$f="Current Raise"}; }; ######## } else { print "$c:\r" }; xte: if(defined $XTE && defined $xte){ print STDERR "$xte\n" if $xte!~/mousermove/; print $XTE "$xte\n"; } xdo: if(defined $xdo){ print STDERR "$xdo\n" if $xdo!~/mousemove_relative/; system"$env xdotool $xdo"; } fvwm: if(defined $f){ print STDERR "$f\n"; system"$env FvwmCommand '$f'"; } }