揮発性のメモ2

http://d.hatena.ne.jp/iww/

入力デバイスの入力をperlで見る

USBヘッドセットについてるボタンの押されっぷりとかを取得する話


とりあえずSYNとかそういうのよくわからないので全部出す

#!/usr/bin/perl

open(my $fh, $ARGV[0]) or die;
binmode($fh);

while( read($fh, my $buf, 16) ){
    my ( $sec,$usec,$type,$code,$value ) = unpack( "LLSSl", $buf );
    print "time=$sec\n";
    print "type=$type\n";
    print "code=$code\n";
    print "value=$value\n";

    if( $type==1 && $value==1 ){
#       if( $code==113 ){ print "MUTE\n" }
#       if( $code==114 ){ print "VOLUMEDOWN\n" }
#       if( $code==115 ){ print "VOLUMEUP\n" }
    }
}

対象機器のtime_tが32bitなので読み込むサイズは 4+4+2+2+4=16 バイト

# ./inputjikken.pl /dev/input/event1
time=1392278238
type=4
code=4
value=786658
time=1392278238
type=1
code=113
value=1
time=1392278238
type=1
code=113
value=0
time=1392278238
type=0
code=0
value=0

ミュートボタン押してみた