Compare commits

..

2 Commits

Author SHA1 Message Date
paring cb2df46a79
feat: use chrono NaiveDateTime 2022-12-08 00:13:13 +09:00
paring d93311a4fb
fix: use two numbers to send current time 2022-12-08 00:12:52 +09:00
1 changed files with 10 additions and 4 deletions

View File

@ -16,7 +16,8 @@ pub enum NativeEventType {
#[repr(C)]
pub struct NativeEvent {
pub time: usize,
pub time_sec: i64,
pub time_nsec: u32,
pub event_type: NativeEventType,
pub vkey: u16,
pub keycode: u16,
@ -32,8 +33,9 @@ fn send_callback(ev: NativeEvent) {
}
}
fn get_time(time: NaiveDateTime) -> usize {
time.timestamp_nanos() as usize
fn get_time(time: NaiveDateTime) -> (i64, u32) {
(time.timestamp(), time.timestamp_subsec_nanos())
}
#[no_mangle]
@ -43,18 +45,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);