Comments (3)
I think the problem is in the key_down for RightArrow since if I have enigo do key_down for Shift then physically hit right arrow it works, so my guess is that the shift key isn't being included in the scancode for the arrow key
from enigo.
Hi, thank you for using my library and taking the time to open the report. I have worked on enigo a lot since version 0.1.3
and fixed many issues (Changelog). I did not get to releasing a new version yet. I tried to replicate the described problem in the current master branch and everything worked as expected. There are two release candidates published on crates.io. I have not tried it with them, but they should work as expected too. In order to use the most recent one, add this to your Cargo.toml
file: enigo = "0.2.0-rc2"
. The API changed a little bit. Here is the code that worked for me:
#[cfg(test)]
mod tests {
// test that sending shift + arrow keys is highlighting text
#[test]
fn test_shift_arrow() {
use crate::{
Direction::{Press, Release},
Enigo, Key, Keyboard, Settings,
};
use std::thread::sleep;
use std::time::Duration;
let mut enigo = Enigo::new(&Settings::default()).unwrap();
sleep(Duration::from_secs(1));
enigo.key(Key::Shift, Press).unwrap();
enigo.key(Key::Control, Press).unwrap();
enigo.key(Key::RightArrow, Press).unwrap();
enigo.key(Key::RightArrow, Release).unwrap();
enigo.key(Key::Control, Release).unwrap();
enigo.key(Key::Shift, Release).unwrap();
}
}
Let me know if that fixes the issue for you too.
from enigo.
Confirmed, using 0.2.0-rc2
has fixed the issue.
Thank you for your work!
I'm using this with Bevy, so I also had to make sure I'm storing the Enigo instance in a local to ensure that state was preserved, otherwise it would continue to forget about shift being held
fn handle_input(
tool_query: Query<&ActionState<KeyboardToolAction>, With<ActiveTool>>,
mut enigo: Local<Option<Enigo>>,
) {
if enigo.is_none() {
*enigo = Enigo::new(&Settings::default()).ok();
}
let Some(ref mut enigo) = *enigo else {
warn!("Failed to create enigo");
return;
};
for tool_actions in tool_query.iter() {
for variant in KeyboardToolAction::variants() {
if tool_actions.just_pressed(variant) {
info!("{:?} key down", variant);
if let Err(e) = enigo.key(variant.to_enigo(), Press) {
warn!("Failed to send key: {:?}", e);
}
}
if tool_actions.just_released(variant) {
info!("{:?} key up", variant);
if let Err(e) = enigo.key(variant.to_enigo(), Release) {
warn!("Failed to send key: {:?}", e);
}
}
}
}
}
from enigo.
Related Issues (20)
- Win: Is it necessary to set the MessageExtraInfo? HOT 1
- win: Use an array in `SendInput` to get rid of sleep HOT 2
- In some games, special keys can't be triggered HOT 13
- Reading key presses HOT 4
- win: Check if alt-gr works
- character sequence manual delay HOT 3
- Inconsistent number of newlines produced by `\n` in `key_sequence` HOT 1
- Is EnigoSettings Unavailable on Windows HOT 2
- Volume up / down doesn't work on MacOS HOT 6
- macOS: Use objc2 instead of objc HOT 3
- Invoking multiple keys at the same time does not seem to register HOT 4
- `text` seems to miss certain characters, consistently HOT 12
- Support BSDs HOT 4
- State of 0.2 releases HOT 6
- Mouse moves to the wrong coordinates HOT 4
- Choose between xdo and wayland at runtime HOT 1
- Doesn't work as expected in simulation “Ctrl+C" HOT 2
- Screenshot under window does not work HOT 1
- Special characters are not working with ShiftKey
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from enigo.