Comments (16)
I worked on something like this to see how we could do Cross platform rust.
https://github.com/Narsil/rdev
It's not compatible with Enigo because I stayed lower level (only raw keycodes for now) but it might be handy for ppl that want to include it in Enigo.
Main caveat, on MacOS you need to be a main app to be able to listen to events AND have enabled accessibility for Terminal or the name of the app. Cheers.
Edit: I didn't do windows code because I don't have access to one right now.
from enigo.
mentioned about that making it blocking, that's not acceptable in some use cases.
we can provide both, something like this:
The idea is that if the underlying api is blocking, then we should not use threads to make it not so. Especially not call it "async" if it's not actually async but rather using threads.
from enigo.
Currently there is no way to listen to events with enigo. We're thinking about it but don't expect this to happen anytime soon because this is a quite involved task to do cross platform and would possibly involve some async system (tokio-'core'?). I just don't have a clear vision about this topic currently.
from enigo.
Seems to be possible on Linux X11 (not with libxdo sadly) to have an event loop, on windows it seems limited to hotkeys, which may be sent to either a window or a thread-local event queue. For mac, I have no idea
from enigo.
@jD91mZM2 how do you think this should be handled from the user perspective? having a register method the that takes a closure? and in the background we start a thread and run an event loop – or somehow try to use tokio stuff?
from enigo.
@pythoneer Since most operating systems' APIs are blocking, I'd suggest we make it blocking as well, and if the user wants it concurrent use threads
from enigo.
@jD91mZM2 this sounds right for now. I was concerned about starting threads because i don't think the user expect that to happen and you don't just start threads out of nowhere. But how should a blocking API should look like for a use case where you want to "register" multiple events?
from enigo.
enigo.register_event(Key::ESC);
for event in enigo.events() {
let event = event?;
// do something with event
}
from enigo.
Ok, just like SDL etc..
from enigo.
Just my idea, seems like the cleanest
from enigo.
looks about right. I think the user can expect it to look like this coming from SDL, win32, or from any other input event handling background.
//EDIT:
I was just thinking about something like
enigo.register(Key::ESC, |evt| println!("escape pressed"));
but i think this is just to problematic
from enigo.
after some googling, just found some good crates that maybe useful
https://github.com/obv-mikhail/InputBot
which i just tried and it works fine*
and also https://github.com/autopilot-rs/autopilot-rs which seems interesting too, as it works with python too https://github.com/autopilot-rs/autopy
if we can have an API as @pythoneer proposed i think it will be good too.
and as @jD91mZM2 mentioned about that making it blocking, that's not acceptable in some use cases.
we can provide both, something like this:
// Call this to start listening for bound inputs.
handle_input_events();
// or async
handle_input_events_async();
anyway i'm ready to help, just make a new issue with a Check list, and we can make it together.
- inputBot works great but seems sometimes have some problem about toggling buttons.
from enigo.
There are two functions in Mac
- InstallEventHandler (Carbon)
- addGlobalMonitorForEventsMatchingMask (Cocoa)
Mac global hotkey in Swift (Carbon)
from enigo.
Is there a WIP on this topic? I'm ready to help too.
from enigo.
@bnau i think no one has actually started a serious effort in this direction as of now.
from enigo.
@pythoneer Okay, thx.
I will fork the project and make a PR as soon as something is ready.
Any idea/suggestion/contribution is welcome!
from enigo.
Related Issues (20)
- In macOS, mouse movement interrupts the press of the meta key. HOT 1
- mouse cannot scroll with diff version HOT 9
- Help getting certain keys to type via Key::Layout HOT 8
- linux: x11rb: Some keys (e.g Tab) do not work HOT 1
- linux: x11rb: Control has no effect if it is the first key HOT 1
- linux: wayland: The Shift key does not work HOT 1
- Scroll lock HOT 10
- 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 12
- 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
- Selecting text isn't working HOT 3
- `text` seems to miss certain characters, consistently HOT 12
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.