Git Product home page Git Product logo

Comments (16)

Narsil avatar Narsil commented on May 31, 2024 3

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.

jD91mZM2 avatar jD91mZM2 commented on May 31, 2024 2

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.

pythoneer avatar pythoneer commented on May 31, 2024

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.

jD91mZM2 avatar jD91mZM2 commented on May 31, 2024

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.

pythoneer avatar pythoneer commented on May 31, 2024

@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.

jD91mZM2 avatar jD91mZM2 commented on May 31, 2024

@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.

pythoneer avatar pythoneer commented on May 31, 2024

@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.

jD91mZM2 avatar jD91mZM2 commented on May 31, 2024
enigo.register_event(Key::ESC);
for event in enigo.events() {
    let event = event?;
    // do something with event
}

from enigo.

pythoneer avatar pythoneer commented on May 31, 2024

Ok, just like SDL etc..

from enigo.

jD91mZM2 avatar jD91mZM2 commented on May 31, 2024

Just my idea, seems like the cleanest

from enigo.

pythoneer avatar pythoneer commented on May 31, 2024

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.

shekohex avatar shekohex commented on May 31, 2024

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.

elbaro avatar elbaro commented on May 31, 2024

There are two functions in Mac

  • InstallEventHandler (Carbon)
  • addGlobalMonitorForEventsMatchingMask (Cocoa)

Mac global hotkey in Swift (Carbon)

from enigo.

bnau avatar bnau commented on May 31, 2024

Is there a WIP on this topic? I'm ready to help too.

from enigo.

pythoneer avatar pythoneer commented on May 31, 2024

@bnau i think no one has actually started a serious effort in this direction as of now.

from enigo.

bnau avatar bnau commented on May 31, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.