Compare commits
1 Commits
main
...
fix/data-s
Author | SHA1 | Date |
---|---|---|
paring | 2d2215ce96 |
19
src/lib.rs
19
src/lib.rs
|
@ -14,7 +14,8 @@ pub enum NativeEventType {
|
|||
|
||||
#[repr(C)]
|
||||
pub struct NativeEvent {
|
||||
pub time: usize,
|
||||
pub time_sec: u64,
|
||||
pub time_nsec: u32,
|
||||
pub event_type: NativeEventType,
|
||||
pub vkey: u16,
|
||||
pub keycode: u16,
|
||||
|
@ -30,8 +31,12 @@ fn send_callback(ev: NativeEvent) {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_time(time: SystemTime) -> usize {
|
||||
time.duration_since(UNIX_EPOCH).unwrap().as_nanos() as usize
|
||||
fn get_time(time: SystemTime) -> (u64, u32) {
|
||||
let dur = time
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.expect("Unable to calculate duration");
|
||||
|
||||
(dur.as_secs(), dur.subsec_nanos())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -41,18 +46,22 @@ pub extern "C" fn start_hook(callback: extern "C" fn(NativeEvent)) -> *const c_c
|
|||
}
|
||||
|
||||
if let Err(e) = skyhook::run(move |event| {
|
||||
let (sec, nsec) = get_time(event.time);
|
||||
|
||||
let event = match event.data {
|
||||
skyhook::types::EventData::KeyPress(label, key) => NativeEvent {
|
||||
time: get_time(event.time),
|
||||
event_type: NativeEventType::KeyPressed,
|
||||
vkey: label as u16,
|
||||
keycode: key,
|
||||
time_sec: sec,
|
||||
time_nsec: nsec,
|
||||
},
|
||||
skyhook::types::EventData::KeyRelease(label, key) => NativeEvent {
|
||||
time: get_time(event.time),
|
||||
event_type: NativeEventType::KeyReleased,
|
||||
vkey: label as u16,
|
||||
keycode: key,
|
||||
time_sec: sec,
|
||||
time_nsec: nsec,
|
||||
},
|
||||
};
|
||||
send_callback(event);
|
||||
|
|
Reference in New Issue