debugging
This commit is contained in:
parent
898f50ecec
commit
0468d32bc1
|
@ -20,12 +20,13 @@ pub enum EventType {
|
||||||
MouseMoveTo { x: f64, y: f64 },
|
MouseMoveTo { x: f64, y: f64 },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct Event {
|
pub struct Event {
|
||||||
pub time: SystemTime,
|
pub time: SystemTime,
|
||||||
pub event_type: EventType,
|
pub event_type: EventType,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type HookCallback = fn(event: Event);
|
// pub type HookCallback = fn(event: Event);
|
||||||
|
pub type HookCallback = for<'a> fn(&'a Event);
|
||||||
|
|
||||||
pub struct Robot;
|
pub struct Robot;
|
||||||
|
|
|
@ -262,7 +262,9 @@ fn default_callback(event: Event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static KEYBOARD_HHOOK: Lazy<AtomicPtr<HHOOK__>> = Lazy::new(AtomicPtr::default);
|
static KEYBOARD_HHOOK: Lazy<AtomicPtr<HHOOK__>> = Lazy::new(AtomicPtr::default);
|
||||||
static mut HOOK_CALLBACK: HookCallback = default_callback;
|
static mut HOOK_CALLBACK: HookCallback = |event| {
|
||||||
|
default_callback(*event);
|
||||||
|
};
|
||||||
|
|
||||||
impl Robot {
|
impl Robot {
|
||||||
pub unsafe fn key_listen(callback: HookCallback) -> Result<(), windows::HookError> {
|
pub unsafe fn key_listen(callback: HookCallback) -> Result<(), windows::HookError> {
|
||||||
|
@ -287,7 +289,9 @@ impl Robot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HOOK_CALLBACK = default_callback;
|
HOOK_CALLBACK = |event| {
|
||||||
|
default_callback(*event);
|
||||||
|
};
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -375,7 +379,7 @@ impl Robot {
|
||||||
event_type,
|
event_type,
|
||||||
time: SystemTime::now(),
|
time: SystemTime::now(),
|
||||||
};
|
};
|
||||||
HOOK_CALLBACK(event);
|
HOOK_CALLBACK(&event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CallNextHookEx(null_mut(), code, w_param, l_param)
|
CallNextHookEx(null_mut(), code, w_param, l_param)
|
||||||
|
|
|
@ -24,7 +24,9 @@ fn default_callback(event: Event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static MOUSE_HHOOK: Lazy<AtomicPtr<HHOOK__>> = Lazy::new(AtomicPtr::default);
|
static MOUSE_HHOOK: Lazy<AtomicPtr<HHOOK__>> = Lazy::new(AtomicPtr::default);
|
||||||
static mut HOOK_CALLBACK: HookCallback = default_callback;
|
static mut HOOK_CALLBACK: HookCallback = |event| {
|
||||||
|
default_callback(*event);
|
||||||
|
};
|
||||||
|
|
||||||
impl Robot {
|
impl Robot {
|
||||||
pub unsafe fn mouse_listen(callback: HookCallback) -> Result<(), windows::HookError> {
|
pub unsafe fn mouse_listen(callback: HookCallback) -> Result<(), windows::HookError> {
|
||||||
|
@ -49,7 +51,9 @@ impl Robot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HOOK_CALLBACK = default_callback;
|
HOOK_CALLBACK = |event| {
|
||||||
|
default_callback(*event);
|
||||||
|
};
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -219,15 +223,13 @@ impl Robot {
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("mouse {:?}", opt);
|
|
||||||
|
|
||||||
if let Some(event_type) = opt {
|
if let Some(event_type) = opt {
|
||||||
let event = Event {
|
let event = Event {
|
||||||
event_type,
|
event_type,
|
||||||
time: SystemTime::now(),
|
time: SystemTime::now(),
|
||||||
};
|
};
|
||||||
|
|
||||||
HOOK_CALLBACK(event);
|
HOOK_CALLBACK(&event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CallNextHookEx(null_mut(), code, w_param, l_param)
|
CallNextHookEx(null_mut(), code, w_param, l_param)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user