enigo-rs / enigo Goto Github PK
View Code? Open in Web Editor NEWCross platform input simulation in Rust
License: MIT License
Cross platform input simulation in Rust
License: MIT License
After upgrading to 0.0.12 from 0.0.11, when I try to compile on Linux (works fine on gnu Windows) it gives error: linking with `cc` failed: exit code: 1
and the reason note: /usr/bin/ld: cannot find -lxdo
The only change to dependencies in 0.0.12 that seem to affect linux is objc 0.2.2
, but when I tried to compile that by itself, it compiled just fine.
I also installed xdo, but that didn't seem to change anything.
Any ideas?
Listing a constructor inside a trait is not very useful i'll guess.
First off let me say that I'm using linux.
I'd like to use this library to control the keyboard programmatically while the user is typing. I really like the API, but sending a character sequence takes a long time, at least 40ms per character due to sleeping 10ms before and after every keydown and keyup, so a single word can easily take half a second to print.
I tried forking and changing those sleep values but if it's too short, not all of the characters print, so I'm guessing they're there for good reason.
I've been looking at plover, which is implemented in python. In plover, they also use XTest to send character sequences, but they render almost instantaneously. I can hammer keys as fast as I can and plover can easily keep up, turning single keystrokes into multi word sequences.
See here https://github.com/openstenoproject/plover/blob/master/plover/oslayer/xkeyboardcontrol.py#L1223
They don't appear to be flushing after every keydown and keyup, but instead appear to be calling display.sync at the end of the key sequence. Is there any way enigo can print entire key sequences instantaneously or is there some limitation there?
Think about a DSL for Keyboard input beyond "just" plain Text.
use an enum for the Mousebutton constants (1=left, 2=right) etc.
In issue #38 we had come to the conclusion that it is beneficial to have a general way to let the user set a way to delay input. It is maybe reasonable to just use the current way it is implemented in linux and make it accessible through the [KeyboardControllable trait](https://github.com/enigo-rs/enigo/blob/949da7042904921530d27a19ebcb2e7bb3615839/src/lib.rs#L330)
Is it possible to send keystrokes to an inactive application? It's unclear to me from the documentation..
Hi, is there is a way to listen to user events. e.g Keyboard events or mouse clicks?
currently i need to listen to some hotkeys e.g "Capslock" toggled so i can make some actions against it.
Thank you.
OS: Arch Linux
Enigo version: 0.0.12
I kept getting a linker error (/usr/bin/ld: cannot find -lxdo
) when building a very simple program, specifically this one:
extern crate enigo;
use enigo::{Enigo, MouseControllable};
fn main() {
let mut enigo = Enigo::new();
enigo.mouse_move_to(500, 200);
}
The error read:
/usr/bin/ld: cannot find -lxdo
on Arch Linux, packages are named differently from Ubuntu. apt install libxdo-dev
(the recommendation from the readme) does not help. To get this working on arch, I had to use
pacman -S xdotool
This command should probably be added to the README. It took me several minutes to discover the right package to install through trial and error, and I thought the enigo crate might simply not work on Arch.
Make the Fields in the Enigo struct private ... i don't think they need to be public.
I found myself wanting to create a struct which held a field of type enigo::Key, so it could pass this every time it has to call an enigo function like key_up
. Unfortunately methods like this one take ownership of the key that one sends in (which is probably a bad idea in itself), and the enum does not derive "Copy, Clone" or other basic traits, and Copy no longer is implicit nowadays.
Practically this means that a user has to hard code which key they want to send and can't store it in a variable, since it can't be copied...
I kind of didn't find any way to work around this except modifying enigo. I will make a pull request for enigo::Key, but other data structures might be affected as well.
investigate how to bound check the mouse cursor (is this necessary? does that cause errors/panics?)
Currently mouse_move doesn't take a screen parameter, which is necessary to be able to specify which monitor.
Instead of the "magic" implementation of getting the screen dimensions in mouse_move_to use the newly added main_display_size for its implementation – no one knows what GetSystemMetrics(78)
means.
After investing more thinkpower into it, i guess these categories fits better.
Hi.
Would it be possible to make a new release to get the fix in #63?
Thanks.
The release of Rust 1.19 offered the new union
which could be applied on the windows implementation to replace the transmute
which is really a union on the c
side of the win api.
https://github.com/enigo-rs/enigo/blob/master/src/win/win_impl.rs#L33
This program on Linux with X11 with xdotool-3.20160805.1 and enigo 0.0.12 gives an error:
let mut enigo = Enigo::new();
enigo.key_sequence_parse(" ");
Error: Invalid key sequence ' '
Failure converting key sequence ' ' to keycodes
Error: Invalid key sequence ' '
Failure converting key sequence ' ' to keycodes
The DSL has a limited amount of buttons that it currently supports. In the first iteration i think its a good idea to support all layout independent ones.
It looks like the failing compilation an macOS *¹ is due to a wrong literal init here
Only unsigned integer possible to move on rasterspace
Implement Serde Serialize and Deserialize traits for Key and MouseButton as optional feature (like in the uuid crate).
use interior mutability to alter internal fields. It is un-ergonomic to bind Enigo mutably.
In the Gitter chat, me and @pythoneer (lead dev) decided using streams for this would be cool.
Imagine something like this: write!(enigo::out, "{}h{}ello {}w{}orld", enigo::shift_on, enigo::shift_off, enigo::shift_on, enigo::shift_off)
stuff
If you send any non-alphanumeric key, enigo seems to just send it directly to xdotool, which it doesn't accept. (it just gives the error Error: Invalid key sequence '.'
or Failure converting key sequence '.' to keycodes
).
List of keys affected:
`
-
=
[
]
\
;
'
,
.
/
I think I can make a PR to fix this.
extern crate enigo;
use enigo::{Enigo, KeyboardControllable, Key};
use std::thread;
use std::time::Duration;
fn main() {
thread::sleep(Duration::from_secs(2));
let mut enigo = Enigo::new();
enigo.key_click(Key::Layout("ä".into()));
}
Hi.
There's a few missing keys like:
Thanks to add them.
Currently the macOS implementation only does left mouse clicks regardless of the function parameter.
just to test the Discord webhook
In the current state it is only possible to build under Linux due to its dependencies. Make it build under macOS, Windows and possibly Redox.
this library behaves differently in release mode vs debug mode.
In debug mode it is quite slow at typing -- it takes around 2-3 seconds to type 20 characters on my laptop.
However, in release mode nothing happens at all! I think the compiler might be optimizing a function away.
I found that the following works in release mode:
fn is_uppercase(c: char) -> bool {
match c {
'A' ... 'Z' => true,
_ => false,
}
}
let mut enigo = enigo::Enigo::new();
println!("sending: {}", password.audit_this);
for c in password.audit_this.chars() {
println!("key: {}", c.to_string());
if is_uppercase(c) {
enigo.key_down(enigo::Key::Shift);
}
enigo.key_down(enigo::Key::Layout(c.to_string()));
enigo.key_up(enigo::Key::Layout(c.to_string()));
if is_uppercase(c) {
enigo.key_up(enigo::Key::Shift);
}
}
It is still rather slow at typing but it works. I wish there were some way to improve the speed.
let the user choose a delay in the public api (only keyboard or for any input?)
Most imports are ::* use finer grained imports.
I am using Windows 10 and the following code:
enigo.key_click(Key::Meta);
But it does nothing, any idea?
if i let this code run, the program crashes
enigo.key_sequence("ä#+ -> hello world ... 𝕊");
enigo.key_click(Key::RETURN);
enigo.key_click(Key::RETURN);
enigo.key_click(Key::RETURN);
enigo.key_click(Key::RETURN);
enigo.key_click(Key::RETURN);
enigo.key_sequence("... how are you? ❤️");
with this error message
X Error of failed request: BadValue (integer parameter out of range for operation)
Major opcode of failed request: 132 (XTEST)
Minor opcode of failed request: 2 (X_XTestFakeInput)
Value in failed request: 0x0
Serial number of failed request: 120
Current serial number in output stream: 122
Hi.
On Linux and a GTK application, sending a key_down(Shift)
won't trigger the key-press-event
for the shift key and thus, the text won't be entered in uppercase.
Could you please add an option to specify the modifier keys so that I could send a character with the Shift modifier?
Thank you.
It looks like CGEventKeyboardSetUnicodeString
truncates strings down to 20 characters, and is undocumented. A few links of other individuals running into this problem:
https://apple.stackexchange.com/a/289046
https://forum.qt.io/topic/46579/cgeventkeyboardsetunicodestring-will-only-process-up-to-20-characters
Is this something we could handle at the enigo mac implementation level? e.g. split key sequence strings into 20 characters and send them in succession?
Hi!
Is there a way to listen to input events? If not, is there a plan to implement it?
We already have implementations for win and mac so we just need one for Linux and are good to go and can implement it on the "general" Enigo struct or on the Mouse Trait but i am unsure if that is the right place for the display size?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.