Skip to content
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

key_click triggers a segmentation fault when called with Key::Layout argument #124

Closed
isharedx opened this issue Dec 4, 2022 · 3 comments

Comments

@isharedx
Copy link
Contributor

isharedx commented Dec 4, 2022

Describe the bug
A segmentation fault is triggered when calling key_click function with a argument of type Key::Layout on MacOS.

To Reproduce

use enigo::{Enigo, Key, KeyboardControllable};
use std::thread;
use std::time::Duration;

fn main() {
    thread::sleep(Duration::from_secs(2));
    let mut enigo = Enigo::new();

    println!("1");
    enigo.key_down(Key::Meta);
    println!("2");
    enigo.key_click(enigo::Key::Layout('c'));
    println!("3");
    enigo.key_up(Key::Meta);
    println!("4");
}

Run with command cargo run, and will get an output as the following:

❯ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.12s
     Running `target/debug/enigo-debug`
1
2
zsh: segmentation fault  cargo run

Expected behavior
No crash, and send a key_click event.

Environment (please complete the following information):

  • OS: macOS Ventura 13.0.1 (22A400)
  • Rust: rustc 1.64.0 (a55dd71d5 2022-09-19)
  • Library Version: enigo 0.0.13

Additional context

@isharedx
Copy link
Contributor Author

isharedx commented Dec 4, 2022

The issue is likely caused by getting the keyboard layout data failed, in this case, the TISGetInputSourceProperty return null and then CFDataGetBytePtr throw an EXC_BAD_ACCESS exception when calling create_string_for_key.

Exception has occurred.
EXC_BAD_ACCESS (code=1, address=0x0)

image

@pentamassiv
Copy link
Collaborator

@pentamassiv
Copy link
Collaborator

The PR was merged so it should be fixed now. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants