Skip to content

Commit

Permalink
macOS: Do not coalesce mouse events to allow precise control (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
pentamassiv authored Sep 10, 2024
1 parent 07fe8f1 commit 01151aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## Changed
- all: The keys `Print` and `Snapshot` were deprecated because `Print` had the wrong virtual key associated with it on Windows. Use `Key::PrintScr` instead
- macOS: The simulated input is no longer effected by the state of the physical keyboard. This default behavior can be changed via the Settings (`independent_of_keyboard_state`)
- macOS: Do not coalesce mouse events to allow precise control

## Added
- all: `Key::PrintScr`
Expand Down
8 changes: 6 additions & 2 deletions src/macos/macos_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use core_foundation::{
use core_graphics::{
display::{CGDisplay, CGPoint},
event::{
CGEvent, CGEventRef, CGEventTapLocation, CGEventType, CGKeyCode, CGMouseButton, EventField,
KeyCode, ScrollEventUnit,
CGEvent, CGEventFlags, CGEventRef, CGEventTapLocation, CGEventType, CGKeyCode,
CGMouseButton, EventField, KeyCode, ScrollEventUnit,
},
event_source::{CGEventSource, CGEventSourceStateID},
};
Expand Down Expand Up @@ -120,6 +120,7 @@ impl Mouse for Enigo {
EventField::EVENT_SOURCE_USER_DATA,
self.event_source_user_data,
);
event.set_flags(CGEventFlags::CGEventFlagNonCoalesced);
event.post(CGEventTapLocation::HID);
}
if direction == Direction::Click || direction == Direction::Release {
Expand Down Expand Up @@ -150,6 +151,7 @@ impl Mouse for Enigo {
EventField::EVENT_SOURCE_USER_DATA,
self.event_source_user_data,
);
event.set_flags(CGEventFlags::CGEventFlagNonCoalesced);
event.post(CGEventTapLocation::HID);
}
Ok(())
Expand Down Expand Up @@ -199,6 +201,7 @@ impl Mouse for Enigo {
EventField::EVENT_SOURCE_USER_DATA,
self.event_source_user_data,
);
event.set_flags(CGEventFlags::CGEventFlagNonCoalesced);
event.post(CGEventTapLocation::HID);
Ok(())
}
Expand Down Expand Up @@ -226,6 +229,7 @@ impl Mouse for Enigo {
EventField::EVENT_SOURCE_USER_DATA,
self.event_source_user_data,
);
event.set_flags(CGEventFlags::CGEventFlagNonCoalesced);
event.post(CGEventTapLocation::HID);
Ok(())
}
Expand Down

0 comments on commit 01151aa

Please sign in to comment.