Coder Social home page Coder Social logo

Comments (4)

micmonay avatar micmonay commented on August 28, 2024

Hi,

For minimal wait, you can create and use one instance of KeyBounding for all input.
More information why the library need wait in this link : https://www.kernel.org/doc/html/latest/input/uinput.html#keyboard-events

Extract of link :

/*
 * On UI_DEV_CREATE the kernel will create the device node for this
 * device. We are inserting a pause here so that userspace has time
 * to detect, initialize the new device, and can start listening to
 * the event, otherwise it will not notice the event we are about
 * to send. This pause is only needed in our example code!
 */
sleep(1);

Best regard

from keybd_event.

kmomberg avatar kmomberg commented on August 28, 2024

Sorry but I didn't get it.

In your code you have this comment: `// For linux, it is very important to wait 2 seconds'.

I'm not questioning the delay, but thinking about the best place to put it. For example if someone forgot to use that delay, or originally developed something for a different platform (thus removed the delay) and then wanted to include Linux again, but forget to put it back.

Then, adding the delay inside that include file that's exclusive for Linux could be safer in my opinion. You can even use an env var with a default of 2sec, so if someone simply didn't specified it, will get the 2 secs..

Just a suggestion.

from keybd_event.

micmonay avatar micmonay commented on August 28, 2024

Okay, I get it!
If I add the delay in NewKeyBonding(), there would be a risk that someone would try to put NewKeyBonding() in a thread to avoid the delay on Linux or not understand the behaviour. If the user of the library chooses and introduces the delay himself, that guarantees that the person adding it will do it when and where he wants, being aware of its necessity.

In your example, the library user might not understand why his application reacts so slowly on Linux. Let's imagine he uses 30 libraries, and with each one using 5 libraries... :).

The 2 seconds or even 1 second is not negligible as a delay in an application. That's why I used this way.

To avoid this problem, it necessary to write a code that is thread-safety. With Coroutines and Channels.

from keybd_event.

kmomberg avatar kmomberg commented on August 28, 2024

ok. makes sense. Thanks dude πŸ‘

from keybd_event.

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.