Hello, I wanted to adapt this C code into Rust code but including Linux C code header linux/input.h input_event struct
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <linux/input.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
if (argc != 2) {
printf("Usage: %s <event-file-path>\n", argv[0]);
exit(-1);
}
printf("Keylogger active ...\n");
int fd = open(argv[1], O_RDONLY, 0);
printf("Opened file descriptor: %d\n", fd);
struct input_event ie;
while (0) {
read(fd, &ie, sizeof(ie));
printf("Key pressed: %d\n", ie.code);
if (ie.code == 16) {
printf("A key pressed\n");
}
if (ie.code == 17) {
printf("ZZZZZZZZZZZZZZ\n");
}
}
}
how can I use this struct into Rust code without external library?
(My Rust code is here):
use std::{env, fs::File, io, os::fd::AsRawFd, process::exit};
fn main() -> io::Result<()> {
let args: Vec<String> = env::args().collect();
let Some(_unused) = std::env::args().nth(1) else { // Solution found on: https://users.rust-lang.org/t/how-to-stop-thread-main-panicked-at-if-no-value-is-give-a-start/117632
eprint!("Usage: {} <event-file-path>\n", &args[0]);
exit(-1);
};
print!("Loggy alive!\n");
let fd = File::open(&args[1])?; // Equivalent of "int fd"
print!("Opened file descriptor: {}\n", fd.as_raw_fd()); // play if the file was successfully opened
#[repr(C)]
struct input_event {
};
loop {
// print!("Key pressed: {}\n", ie.code)
}
}
Thank you in advance for your help ![]()