-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
*mut core_graphics::sys::macos::CGEventSource` cannot be sent between threads safely #96
Comments
Hi and thanks for opening the issue. Unfortunately i am currently not able to investigate this further due to my mac being unavailable for a short time. But just from reading the issue it looks like you are trying to send Enigo into another thread and it appears that this is not safe to do (at least on macOS). Can you try to instantiate the Enigo instance inside your callback? move |stamp, message, _| {
let keystroke = Enigo::new(); // moved the instantiation to this place
println!("{}: {:?} (len = {})", stamp, message, message.len());
if message[0] == 144 && message[1] == 60 {
keystroke.key_sequence_parse("{+META}{-META}");
}
println!("{}: Matched MIDI input, sending configured keystroke", stamp)
} |
Hi there! It definitely works and it compiles without any issues – thank you. |
I'm doing something very similar and running into the same problem. Creating a new
So I used a channel so that the use tokio::sync::mpsc;
use enigo::{Enigo, Key, KeyboardControllable};
pub enum EnigoCommand {
KeyClick(Key),
KeyDown(Key),
KeyUp(Key),
}
#[tokio::main]
async fn main() {
let mut enigo = Enigo::new();
let (ch_tx, mut ch_rx) = mpsc::unbounded_channel::<EnigoCommand>();
tokio::spawn(async move {
// application specific stuff...
// send commands to ch_tx
ch_tx.send(EnigoCommand::KeyClick(Key::Layout('E')));
});
while let Some(command) = ch_rx.recv().await {
match command {
EnigoCommand::KeyClick(key) => enigo.key_click(key),
EnigoCommand::KeyDown(key) => enigo.key_down(key),
EnigoCommand::KeyUp(key) => enigo.key_up(key),
}
}
} It would be nice if |
There has not been any progress in making Enigo safe to send, but we do have something like the command enum now. They are called Token. The serde example demonstrates how to use them. |
Describe the bug
I'm trying to write a simple program that handles incoming MIDI and sends keystrokes based on that. Unfortunately, I cannot compile written code due to Traits not being implemented.
Error from VS Code
To Reproduce
Besically, the code here is straight from midir example, with couple of added lines:
Environment (please complete the following information):
Additional context
Don't think it's the problem with midir, but might be good to check there as well. I'm not very well versed with Rust just yet.
The text was updated successfully, but these errors were encountered: