Skip to content

Instantly share code, notes, and snippets.

@Acconut
Created May 26, 2016 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Acconut/1d31c1d04430cfa144437bd9c81e541e to your computer and use it in GitHub Desktop.
Save Acconut/1d31c1d04430cfa144437bd9c81e541e to your computer and use it in GitHub Desktop.
#![feature(read_exact)]
use std::fs::File;
use std::io::Read;
use std::mem::transmute;
#[derive(Debug)]
struct RawEvent {
time_a: i64,
time_b: i64,
typ: u16,
code: u16,
value: i32
}
fn main() {
let mut f = File::open("/dev/input/event16").unwrap();
let mut buf: [u8; 24] = [0; 24];
loop {
f.read_exact(&mut buf).unwrap();
let ev: RawEvent = unsafe { transmute(buf) };
if ev.typ == 0 {
continue
}
println!("event: {:?}", ev);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment