Compare commits
No commits in common. "cb2df46a799b3e4a113543f47bbd99e6098e853d" and "663da661385f8aaa60a83bd5e1c4077192b41187" have entirely different histories.
cb2df46a79
...
663da66138
14
src/lib.rs
14
src/lib.rs
|
@ -16,8 +16,7 @@ pub enum NativeEventType {
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct NativeEvent {
|
pub struct NativeEvent {
|
||||||
pub time_sec: i64,
|
pub time: usize,
|
||||||
pub time_nsec: u32,
|
|
||||||
pub event_type: NativeEventType,
|
pub event_type: NativeEventType,
|
||||||
pub vkey: u16,
|
pub vkey: u16,
|
||||||
pub keycode: u16,
|
pub keycode: u16,
|
||||||
|
@ -33,9 +32,8 @@ fn send_callback(ev: NativeEvent) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_time(time: NaiveDateTime) -> usize {
|
||||||
time.timestamp_nanos() as usize
|
time.timestamp_nanos() as usize
|
||||||
fn get_time(time: NaiveDateTime) -> (i64, u32) {
|
|
||||||
(time.timestamp(), time.timestamp_subsec_nanos())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -45,22 +43,18 @@ pub extern "C" fn start_hook(callback: extern "C" fn(NativeEvent)) -> *const c_c
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = skyhook::run(move |event| {
|
if let Err(e) = skyhook::run(move |event| {
|
||||||
let (sec, nsec) = get_time(event.time);
|
|
||||||
|
|
||||||
let event = match event.data {
|
let event = match event.data {
|
||||||
skyhook::types::EventData::KeyPress(label, key) => NativeEvent {
|
skyhook::types::EventData::KeyPress(label, key) => NativeEvent {
|
||||||
|
time: get_time(event.time),
|
||||||
event_type: NativeEventType::KeyPressed,
|
event_type: NativeEventType::KeyPressed,
|
||||||
vkey: label as u16,
|
vkey: label as u16,
|
||||||
keycode: key,
|
keycode: key,
|
||||||
time_sec: sec,
|
|
||||||
time_nsec: nsec,
|
|
||||||
},
|
},
|
||||||
skyhook::types::EventData::KeyRelease(label, key) => NativeEvent {
|
skyhook::types::EventData::KeyRelease(label, key) => NativeEvent {
|
||||||
|
time: get_time(event.time),
|
||||||
event_type: NativeEventType::KeyReleased,
|
event_type: NativeEventType::KeyReleased,
|
||||||
vkey: label as u16,
|
vkey: label as u16,
|
||||||
keycode: key,
|
keycode: key,
|
||||||
time_sec: sec,
|
|
||||||
time_nsec: nsec,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
send_callback(event);
|
send_callback(event);
|
||||||
|
|
Reference in New Issue