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 causes app crash when using Tauri #153

Open
jackeydou opened this issue Feb 26, 2023 · 21 comments
Open

key_click causes app crash when using Tauri #153

jackeydou opened this issue Feb 26, 2023 · 21 comments

Comments

@jackeydou
Copy link

Describe the bug
Application will crash when calling key_click function;

To Reproduce

let mut enigo = Enigo::new();
enigo.key_down(Key::Meta);
let key_c = Key::Layout('c');
enigo.key_click(key_c);
enigo.key_up(Key::Meta);

Expected behavior
No crash.

Environment (please complete the following information):

  • OS: macOS Ventura 13.0 (22A380), Apple silicon
  • Rust: rustc 1.66.0 (69f9c33d7 2022-12-12)
  • Library Version: engio master branch

Additional context
I have read this pr #124 and I use the master branch of this crate, but I still have the problem in create_string_for_key fn.
code screenshot
I try to debug it, and when the code executes to the TISGetInputSourceProperty the application will crash.

Exception has occurred.
EXC_BREAKPOINT (code=1, subcode=0x1b346d924)
@pentamassiv
Copy link
Collaborator

Hmm, that's not good. In a few days I should be able to borrow a Mac and then I can try it myself. Which keyboard layout are you using? Maybe it has to do with that?

@jackeydou
Copy link
Author

Hmm, that's not good. In a few days I should be able to borrow a Mac and then I can try it myself. Which keyboard layout are you using? Maybe it has to do with that?

I tried the Chinese layout and English layout, and both of them have the same problem.

I find a simple demo of the usage of TISCopyCurrentKeyboardInputSource in stackoverflow, and I executed the code below, it runs ok, that's so weird.

#include <Carbon/Carbon.h>
int main() {
    char layout[128];
    memset(layout, '\0', sizeof(layout));
    TISInputSourceRef source = TISCopyCurrentKeyboardInputSource();
    // get input source id - kTISPropertyInputSourceID
    // get layout name - kTISPropertyLocalizedName
    CFStringRef layoutID = TISGetInputSourceProperty(source, kTISPropertyInputSourceID);
    CFStringGetCString(layoutID, layout, sizeof(layout), kCFStringEncodingUTF8);
    printf("%s\n", layout);
    return 0;
}

@pentamassiv
Copy link
Collaborator

Thank you for your feedback. One last chance would be that it was a problem with the core_graphics crate and it was already fixed. Could you please try with the changes from #131? If that also fails, I need to look into it on a mac. I hope I will be able to reproduce it so I can investigate it.

@jackeydou
Copy link
Author

jackeydou commented Feb 27, 2023

I clone the repo, override the crate in my project, and upgrade the core-graphics crate, but the problem remains.

[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.2", features = ["app-all", "clipboard-all", "global-shortcut-all", "http-all", "shell-open"] }
enigo = "0.0.14"

[patch.crates-io]
enigo = { path = "../../../github/enigo" }

@pentamassiv pentamassiv added the macOS macOS specific label Feb 27, 2023
@pentamassiv
Copy link
Collaborator

Okay, I created a new PR to fix it. Could you please try with that branch?
#161

@mino01x
Copy link

mino01x commented Mar 23, 2023

I encountered the same problem while using Tauri. I tried running cargo run --example keyboard in the master branch, and it worked. However, upon further investigation, I discovered that the code of the crate I had installed was different from that in the master branch. Therefore, I switched to the last published commit and ran cargo run --example keyboard, but still faced the same issue.

@pentamassiv
Copy link
Collaborator

Yes, that is a known problem with Tauri. Unfortunately we currently do not know why this happens. Any insight into it would be very much appreciated. I tried out a bunch of stuff but nothing fixed it. There is an open ticket in the tauri repo tauri-apps/tauri#6421 but so far there has not been any activity on it.
I probably will not have the time to look into Tauri for the next couple of months to investigate this further. Any help on this would be very much appreciated :)

@pentamassiv pentamassiv changed the title key_click causes app crash key_click causes app crash when using Tauri Mar 23, 2023
@mino01x
Copy link

mino01x commented Mar 23, 2023

i published crate enigo-copy@v0.0.14 from the master branch and tested it, it works for me.

@pentamassiv
Copy link
Collaborator

I am glad it works for you with the code from master. Were you not able to use:
enigo = { git = "https://github.com/enigo-rs/enigo" }
in your Cargo.toml file or how come you published it on crates.io?

@mino01x
Copy link

mino01x commented Mar 27, 2023

i didn't expect to there to be such a method, my poor knowledge. thank u

@pentamassiv
Copy link
Collaborator

Okay, no problem. It is impossible to delete crates from crates.io, so it is recommended to use a git dependency if you want to try out things like this. Otherwise all names will be used up and authors of libraries will have a problem to find a good name. It is unlikely anybody would want to publish a library under the name enigo-copy, so it's no problem :)

@frasermince
Copy link

Hey just wanted to jump in on this. Even after setting my enigo crate to master I am still seeing this issue. Any idea if there's currently a fix for this?

@pentamassiv
Copy link
Collaborator

Yes, this is still a known issue even on master. I don't know what the issue is so I can't fix it. There also has not been any activity in the issue opened in the tauri repo. If you want to look into the root cause, I would be very glad to fix it

@ufon
Copy link

ufon commented Apr 4, 2023

OK I tested enigo with tauri in only mouse mode and it works well. So the problem is only with the key_click method.

Also, I run directly keyboard example from enigo and it works well too.

Mac OSX Ventura 13.2.1, M1 Max

@alaninnovates
Copy link

Any updates here? Or is this just frozen-in-place? I'm still having this on macos ventura (13.1)

@pentamassiv
Copy link
Collaborator

I did not have the time to check it out. I wanted to add wayland support and x11 support without xdotools before. There is an issue at the tauri repo where a fix was suggested but nobody seemed to have tried it:
tauri-apps/tauri#6421 (comment)

@pentamassiv pentamassiv pinned this issue May 10, 2023
@gaandurian
Copy link

I did not have the time to check it out. I wanted to add wayland support and x11 support without xdotools before. There is an issue at the tauri repo where a fix was suggested but nobody seemed to have tried it: tauri-apps/tauri#6421 (comment)

Tried it, same problem

@pentamassiv
Copy link
Collaborator

Okay, thank you for trying it out

@Fleebee
Copy link

Fleebee commented Feb 24, 2024

To anybody still having this issue.
One of my deployment platforms is a macbook on catalina . Intel chip 2013 and randomly started crashing with enigo keypresses. Frustratingly It crashes without any error output.
Specifically :
enigo.key_sequence("String I want to type");

In my tauri main i added startup_tests(); to the beginning which is just a fn that moves the mouse and simulates keypresses.

fn startup_tests() {
    let mut enigo = Enigo::new();
    enigo.mouse_move_to(800, 500);
    enigo.key_down(Key::Control);
    enigo.key_click(Key::Layout('c'));
    enigo.key_up(Key::Control);
}

I also set the enigo version to "0.1.0"

I did this to test if it also crashed on startup, it didnt and suddenly the invoked function from within my app was also no longer crashing the project.

I'm not sure why this worked but it no longer crashes .
I also didnt have this issue on an M1 mac or windows machine

@qzd1989
Copy link

qzd1989 commented Sep 6, 2024

same problem here..... I should saw this issue before.... -_-

@pentamassiv
Copy link
Collaborator

pentamassiv commented Oct 28, 2024

I created a simple Tauri project. It is using Tauri 2.0 and the latest unreleased version of enigo. Please run it and let me know if it crashes. It worked fine for me on a Mac.

You can run run it by executing the command
pnpm tauri dev in the project folder. The program does nothing until you press the keys Ctrl+Alt+n. Then it presses keys to copy and then delete the highlighted text.

Please note that it's likely not the best way to use enough with Tauri because the enigo struct gets created each time. The project will also not work on Linux.

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

9 participants