Also added a keyboard delay handler just in case...
This commit is contained in:
parent
b87edceb86
commit
6efdce4d43
25
src/main.rs
25
src/main.rs
|
@ -117,7 +117,8 @@ fn main() -> error::Result<()> {
|
|||
thread::spawn(move || {
|
||||
let input = input();
|
||||
input.enable_mouse_mode().unwrap();
|
||||
let mut input_timer = Instant::now();
|
||||
let mut mouse_timer = Instant::now();
|
||||
let mut keyboard_timer = Instant::now();
|
||||
|
||||
// TODO: I don't like this... seems odd async doesn't work on linux (then again, sync didn't work on windows)
|
||||
if cfg!(target_os = "linux") {
|
||||
|
@ -125,16 +126,19 @@ fn main() -> error::Result<()> {
|
|||
for event in reader {
|
||||
match event {
|
||||
InputEvent::Keyboard(key) => {
|
||||
if tx.send(Event::KeyInput(key)).is_err() {
|
||||
return;
|
||||
if Instant::now().duration_since(keyboard_timer).as_millis() >= 10 {
|
||||
if tx.send(Event::KeyInput(key)).is_err() {
|
||||
return;
|
||||
}
|
||||
keyboard_timer = Instant::now();
|
||||
}
|
||||
}
|
||||
InputEvent::Mouse(mouse) => {
|
||||
if Instant::now().duration_since(input_timer).as_millis() >= 40 {
|
||||
if Instant::now().duration_since(mouse_timer).as_millis() >= 40 {
|
||||
if tx.send(Event::MouseInput(mouse)).is_err() {
|
||||
return;
|
||||
}
|
||||
input_timer = Instant::now();
|
||||
mouse_timer = Instant::now();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
@ -147,16 +151,19 @@ fn main() -> error::Result<()> {
|
|||
if let Some(event) = reader.next() {
|
||||
match event {
|
||||
InputEvent::Keyboard(key) => {
|
||||
if tx.send(Event::KeyInput(key)).is_err() {
|
||||
return;
|
||||
if Instant::now().duration_since(keyboard_timer).as_millis() >= 10 {
|
||||
if tx.send(Event::KeyInput(key)).is_err() {
|
||||
return;
|
||||
}
|
||||
keyboard_timer = Instant::now();
|
||||
}
|
||||
}
|
||||
InputEvent::Mouse(mouse) => {
|
||||
if Instant::now().duration_since(input_timer).as_millis() >= 40 {
|
||||
if Instant::now().duration_since(mouse_timer).as_millis() >= 40 {
|
||||
if tx.send(Event::MouseInput(mouse)).is_err() {
|
||||
return;
|
||||
}
|
||||
input_timer = Instant::now();
|
||||
mouse_timer = Instant::now();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
|
Loading…
Reference in New Issue