Segmentation fault on keypress (OSX)
OS: OSX (Terminal.app has been add to Accessibility->Privacy)
use rdev::{listen, Event};
fn main() {
// This will block.
if let Err(error) = listen(callback) {
println!("Error: {:?}", error)
}
fn callback(event: Event) {
println!("My callback {:?}", event);
match event.name {
Some(string) => println!("User wrote {:?}", string),
None => (),
}
}
}
cargo run
Mouse move & click are succesfully listened but whenever I press any key the program exist with
Segmentation fault: 11
i got the same issue, but only if the listen(callback) is invoked in a new thread to make it not blocking (tauri framework)
also, i am on osx.
vscode, terminal & app are allowed to listen to keyboard events and so on, i have checked the entire osx settings list
fn create_device_query_listener(handle: tauri::AppHandle) {
//! keyboard key press will freeze, if run in another thread
std::thread::spawn(move || {
let mut alt_pressed = false;
let mut tab_pressed = false;
let mut coords_on_open = Vector2::new(0.0, 0.0);
let mut coords_current = Vector2::new(0.0, 0.0);
let mut win_visible = false;
let callback = move |event: Event| {
// println!("My callback {:?}", event);
// return ;
match event.event_type {
KeyRelease(key) => {
if key == Alt {
alt_pressed = false;
} else if key == Tab {
tab_pressed = false;
}
}
KeyPress(key) => {
if key == Alt {
alt_pressed = true;
} else if key == Tab {
tab_pressed = true;
}
}
MouseMove { x, y } => {
coords_current = Vector2::new(x as f32, y as f32);
println!("mouse: x {} y {}", x , y);
}
_ => println!("event ignored")
}
// {
// println!("alt: {}, tab: {}", alt_pressed, tab_pressed);
// }
if alt_pressed && tab_pressed {
println!("alt tab pressed");
if win_visible == false {
win_visible = true;
coords_on_open = coords_current.clone();
show_window(&handle, &coords_on_open)
}
let angle = get_angle(&coords_on_open, &coords_current);
let distance = get_distance(&coords_on_open, &coords_current);
transfer_angle_distance_to_window(&handle, &angle, &distance);
} else {
win_visible = false;
}
};
if let Err(error) = listen(callback) {
println!("Error: {:?}", error)
}
});
}
I got the same issue
i got the same issue, but only if the
listen(callback)is invoked in a new thread to make it not blocking (tauri framework) also, i am on osx.vscode, terminal & app are allowed to listen to keyboard events and so on, i have checked the entire osx settings list
fn create_device_query_listener(handle: tauri::AppHandle) { //! keyboard key press will freeze, if run in another thread std::thread::spawn(move || { let mut alt_pressed = false; let mut tab_pressed = false; let mut coords_on_open = Vector2::new(0.0, 0.0); let mut coords_current = Vector2::new(0.0, 0.0); let mut win_visible = false; let callback = move |event: Event| { // println!("My callback {:?}", event); // return ; match event.event_type { KeyRelease(key) => { if key == Alt { alt_pressed = false; } else if key == Tab { tab_pressed = false; } } KeyPress(key) => { if key == Alt { alt_pressed = true; } else if key == Tab { tab_pressed = true; } } MouseMove { x, y } => { coords_current = Vector2::new(x as f32, y as f32); println!("mouse: x {} y {}", x , y); } _ => println!("event ignored") } // { // println!("alt: {}, tab: {}", alt_pressed, tab_pressed); // } if alt_pressed && tab_pressed { println!("alt tab pressed"); if win_visible == false { win_visible = true; coords_on_open = coords_current.clone(); show_window(&handle, &coords_on_open) } let angle = get_angle(&coords_on_open, &coords_current); let distance = get_distance(&coords_on_open, &coords_current); transfer_angle_distance_to_window(&handle, &angle, &distance); } else { win_visible = false; } }; if let Err(error) = listen(callback) { println!("Error: {:?}", error) } }); }
this is the code
app.run(|app_handler, run_event| {
tauri::async_runtime::spawn(async move {
listen(move |event| match event.event_type {
EventType::KeyPress(Key::Alt) => {
println!("alt")
}
_ => {}
})
.expect("error");
});
});
I had the same issue too (tauri / MacOS / segfault on keypress) But this fixed the problem ✅
(@Narsil, maybe you should consider pull back the changes made on this fork ?)
Please do pull the changes if possible, it would be very helpful