1
0
mirror of https://github.com/Toxblh/MTMR.git synced 2026-01-10 17:08:39 +00:00

switch hidKeys to obj-c realesation

This commit is contained in:
Toxblh 2018-05-10 09:56:04 +02:00
parent d048ec851e
commit 33efbbebaa
3 changed files with 6 additions and 33 deletions

View File

@ -10,8 +10,6 @@
@interface MediaKeys : NSObject
+ (void)decreaseVolume;
+ (void)increaseVolume;
+ (void)muteVolume;
+ (void)HIDPostAuxKey:(UInt8)keyCode;
@end

View File

@ -31,7 +31,7 @@ static io_connect_t get_event_driver(void)
}
static void HIDPostAuxKey( const UInt8 auxKeyCode )
static void HIDReleaseAuxKey( const UInt8 auxKeyCode )
{
NXEventData event;
kern_return_t kr;
@ -52,16 +52,8 @@ static void HIDPostAuxKey( const UInt8 auxKeyCode )
kr = IOHIDPostEvent( get_event_driver(), NX_SYSDEFINED, loc, &event, kNXEventDataVersion, 0, FALSE );
}
+ (void)decreaseVolume {
HIDPostAuxKey(NX_KEYTYPE_SOUND_DOWN);
}
+ (void)increaseVolume {
HIDPostAuxKey(NX_KEYTYPE_SOUND_UP);
}
+ (void)muteVolume {
HIDPostAuxKey(NX_KEYTYPE_MUTE);
+ (void)HIDPostAuxKey: (UInt8)keyCode {
HIDReleaseAuxKey(keyCode);
}
@end

View File

@ -29,24 +29,7 @@ extension KeyPress {
}
}
func doKey(_ key: UInt16, down: Bool) {
let ev = NSEvent.keyEvent(
with: down ? .keyDown : .keyUp,
location: .zero,
modifierFlags: [],
timestamp: TimeInterval(0),
windowNumber: 0,
context: nil,
characters: "",
charactersIgnoringModifiers: "",
isARepeat: false,
keyCode: key)
let cev = ev!.cgEvent!
cev.post(tap: CGEventTapLocation(rawValue: 0)!)
}
func HIDPostAuxKey(_ key: Int32) {
let key = UInt16(key)
doKey(key, down: true)
doKey(key, down: false)
let key = UInt8(key)
MediaKeys.hidPostAuxKey(key)
}