-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83202ea
commit 1ead76d
Showing
3 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "debug_macos" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
core-graphics = "0.22" | ||
objc = "0.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use core_graphics::event::{ | ||
CGEvent, CGEventFlags, CGEventTap, CGEventTapLocation, CGEventType, EventField, | ||
}; | ||
use core_graphics::sys::CGEventMask; | ||
use std::ptr; | ||
|
||
fn main() { | ||
// Set up an event tap for key down and key up events | ||
let event_mask = CGEventMask(1 << CGEventType::KeyDown as u64 | 1 << CGEventType::KeyUp as u64); | ||
|
||
unsafe { | ||
let tap = CGEventTap::new( | ||
CGEventTapLocation::HID, | ||
CGEventType::KeyDown, | ||
event_mask, | ||
move |event| { | ||
// Access the event's flags | ||
let flags = event.get_flags(); | ||
|
||
// Print the flags (e.g., control, shift, command, etc.) | ||
println!("Key Event with flags: {:?}", flags); | ||
|
||
// You can get specific keys like so: | ||
if flags.contains(CGEventFlags::CGEventFlagMaskShift) { | ||
println!("Shift key is pressed"); | ||
} | ||
if flags.contains(CGEventFlags::CGEventFlagMaskControl) { | ||
println!("Control key is pressed"); | ||
} | ||
if flags.contains(CGEventFlags::CGEventFlagMaskCommand) { | ||
println!("Command key is pressed"); | ||
} | ||
|
||
// Pass the event through to the next receiver | ||
event | ||
}, | ||
) | ||
.expect("Failed to create event tap"); | ||
|
||
tap.start().expect("Failed to start event tap"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters