Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
macOS: Remove all sleeps and add one when the
Enigo
struct is dropped
There were two reasons why we needed to sleep on macOS. The OS needed "some time" to apply a modifier and correctly set the CGEventFlags. We can remove the sleep and manually set the flags. Another reason for the sleeps is that all pending events get ignored when the program terminates. The sleeps were needed so that the OS had enough time to handle all events before the Enigo struct gets dropped. Sleeps during the execution are much more annoying then at the end of the program, so there is now a sleep for two seconds when the Enigo struct gets dropped. I just assumed that to be enough for most cases. I did not find a way to ask the OS if all events were handled. We could probably do better here and calculate a duration based on the time when the last event was sent and how many were sent. Other things that were fixed: - Thanks to the sleep in the Drop trait of Enigo, moving the mouse also works if it is the only function that gets executed. It used to finish too fast and we didn't have a sleep so it got ignored because Enigo was dropped before it was handled by the OS - By manually setting the EventFlags, CapsLock now also works. Before this commit, sending text would fail if a modifier was held and the text was too small to be sent as one chunk.
- Loading branch information