Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
pentamassiv committed Jan 6, 2024
1 parent 8a8b32b commit 2044d04
Showing 1 changed file with 63 additions and 63 deletions.
126 changes: 63 additions & 63 deletions src/macos/macos_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,69 +418,6 @@ impl Keyboard for Enigo {

Ok(())
}

fn special_keys(key: Key) -> InputResult<()> {
// Simulate illumination up
// let code = NX_KEYTYPE_ILLUMINATION_UP;

let event = unsafe {
AppKit::NSEvent::otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2(
NSEventType::NSEventTypeSystemDefined,
NSPoint::ZERO,
NSEventModifierFlags,
0,
0,
None,
8,
555,
555
)
}; //-> Option<Id<NSEvent>>

let Some(event) = event else {
return Err(InputError::Simulate(
"failed creating event to enter special keys",
));
};

event.post(CGEventTapLocation::HID);

/*
let event1 = NSEvent.otherEvent(with: .systemDefined, location: NSPoint.zero, modifierFlags: NSEventModifierFlags(rawValue: 0xa00), timestamp: 0, windowNumber: 0, context: nil, subtype: 8, data1: (Int((code << 16 as Int32) | (0xa << 8 as Int32))), data2: -1)
event1?.cgEvent?.post(tap: .cghidEventTap)
let event2 = NSEvent.otherEvent(with: .systemDefined, location: NSPoint.zero, modifierFlags: NSEventModifierFlags(rawValue: 0xb00), timestamp: 0, windowNumber: 0, context: nil, subtype: 8, data1: (Int((code << 16 as Int32) | (0xb << 8 as Int32))), data2: -1)
event2?.cgEvent?.post(tap: .cghidEventTap)
// Simulate illumination down
let code = NX_KEYTYPE_ILLUMINATION_DOWN
let event1 = NSEvent.otherEvent(with: .systemDefined, location: NSPoint.zero, modifierFlags: NSEventModifierFlags(rawValue: 0xa00), timestamp: 0, windowNumber: 0, context: nil, subtype: 8, data1: (Int((code << 16 as Int32) | (0xa << 8 as Int32))), data2: -1)
event1?.cgEvent?.post(tap: .cghidEventTap)
let event2 = NSEvent.otherEvent(with: .systemDefined, location: NSPoint.zero, modifierFlags: NSEventModifierFlags(rawValue: 0xb00), timestamp: 0, windowNumber: 0, context: nil, subtype: 8, data1: (Int((code << 16 as Int32) | (0xb << 8 as Int32))), data2: -1)
event2?.cgEvent?.post(tap: .cghidEventTap)
/* Mask of special keys that are posted as events */
#define NX_SPECIALKEY_POST_MASK \
((1 << NX_KEYTYPE_SOUND_UP) | (1 << NX_KEYTYPE_SOUND_DOWN) | \
(1 << NX_POWER_KEY) | (1 << NX_KEYTYPE_MUTE) | \
(1 << NX_KEYTYPE_BRIGHTNESS_UP) | (1 << NX_KEYTYPE_BRIGHTNESS_DOWN) | \
(1 << NX_KEYTYPE_CONTRAST_UP) | (1 << NX_KEYTYPE_CONTRAST_UP) | \
(1 << NX_KEYTYPE_LAUNCH_PANEL) | (1 << NX_KEYTYPE_EJECT) | \
(1 << NX_KEYTYPE_VIDMIRROR) | (1 << NX_KEYTYPE_PLAY) | \
(1 << NX_KEYTYPE_NEXT) | (1 << NX_KEYTYPE_PREVIOUS) | \
(1 << NX_KEYTYPE_FAST) | (1 << NX_KEYTYPE_REWIND) | \
(1 << NX_KEYTYPE_ILLUMINATION_UP) | \
(1 << NX_KEYTYPE_ILLUMINATION_DOWN) | \
(1 << NX_KEYTYPE_ILLUMINATION_TOGGLE) | 0)
*/
}
}

impl Enigo {
Expand Down Expand Up @@ -559,6 +496,69 @@ impl Enigo {
debug!("nth_button_press: {nth_button_press}");
nth_button_press
}

fn special_keys(key: Key) -> InputResult<()> {
// Simulate illumination up
// let code = NX_KEYTYPE_ILLUMINATION_UP;

let event = unsafe {
AppKit::NSEvent::otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2(
NSEventType::NSEventTypeSystemDefined,
NSPoint::ZERO,
NSEventModifierFlags,
0,
0,
None,
8,
555,
555
)
}; //-> Option<Id<NSEvent>>

let Some(event) = event else {
return Err(InputError::Simulate(
"failed creating event to enter special keys",
));
};

event.post(CGEventTapLocation::HID);

/*
let event1 = NSEvent.otherEvent(with: .systemDefined, location: NSPoint.zero, modifierFlags: NSEventModifierFlags(rawValue: 0xa00), timestamp: 0, windowNumber: 0, context: nil, subtype: 8, data1: (Int((code << 16 as Int32) | (0xa << 8 as Int32))), data2: -1)
event1?.cgEvent?.post(tap: .cghidEventTap)
let event2 = NSEvent.otherEvent(with: .systemDefined, location: NSPoint.zero, modifierFlags: NSEventModifierFlags(rawValue: 0xb00), timestamp: 0, windowNumber: 0, context: nil, subtype: 8, data1: (Int((code << 16 as Int32) | (0xb << 8 as Int32))), data2: -1)
event2?.cgEvent?.post(tap: .cghidEventTap)
// Simulate illumination down
let code = NX_KEYTYPE_ILLUMINATION_DOWN
let event1 = NSEvent.otherEvent(with: .systemDefined, location: NSPoint.zero, modifierFlags: NSEventModifierFlags(rawValue: 0xa00), timestamp: 0, windowNumber: 0, context: nil, subtype: 8, data1: (Int((code << 16 as Int32) | (0xa << 8 as Int32))), data2: -1)
event1?.cgEvent?.post(tap: .cghidEventTap)
let event2 = NSEvent.otherEvent(with: .systemDefined, location: NSPoint.zero, modifierFlags: NSEventModifierFlags(rawValue: 0xb00), timestamp: 0, windowNumber: 0, context: nil, subtype: 8, data1: (Int((code << 16 as Int32) | (0xb << 8 as Int32))), data2: -1)
event2?.cgEvent?.post(tap: .cghidEventTap)
/* Mask of special keys that are posted as events */
#define NX_SPECIALKEY_POST_MASK \
((1 << NX_KEYTYPE_SOUND_UP) | (1 << NX_KEYTYPE_SOUND_DOWN) | \
(1 << NX_POWER_KEY) | (1 << NX_KEYTYPE_MUTE) | \
(1 << NX_KEYTYPE_BRIGHTNESS_UP) | (1 << NX_KEYTYPE_BRIGHTNESS_DOWN) | \
(1 << NX_KEYTYPE_CONTRAST_UP) | (1 << NX_KEYTYPE_CONTRAST_UP) | \
(1 << NX_KEYTYPE_LAUNCH_PANEL) | (1 << NX_KEYTYPE_EJECT) | \
(1 << NX_KEYTYPE_VIDMIRROR) | (1 << NX_KEYTYPE_PLAY) | \
(1 << NX_KEYTYPE_NEXT) | (1 << NX_KEYTYPE_PREVIOUS) | \
(1 << NX_KEYTYPE_FAST) | (1 << NX_KEYTYPE_REWIND) | \
(1 << NX_KEYTYPE_ILLUMINATION_UP) | \
(1 << NX_KEYTYPE_ILLUMINATION_DOWN) | \
(1 << NX_KEYTYPE_ILLUMINATION_TOGGLE) | 0)
*/
}
}

/// Converts a `Key` to a `CGKeyCode`
Expand Down

0 comments on commit 2044d04

Please sign in to comment.