aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dome_key_event_source_simulator/dome_key_event_source_simulator.h5
-rw-r--r--dome_key_event_source_simulator/dome_key_event_source_simulator.m28
2 files changed, 32 insertions, 1 deletions
diff --git a/dome_key_event_source_simulator/dome_key_event_source_simulator.h b/dome_key_event_source_simulator/dome_key_event_source_simulator.h
index 548e17b..9ccc35d 100644
--- a/dome_key_event_source_simulator/dome_key_event_source_simulator.h
+++ b/dome_key_event_source_simulator/dome_key_event_source_simulator.h
@@ -6,8 +6,11 @@
// Copyright © 2018 tw. All rights reserved.
//
-#import <Foundation/Foundation.h>
+#import <Cocoa/Cocoa.h>
@interface dome_key_event_source_simulator : NSObject
@end
+
+
+void dkess_press_key(int key, NSEventModifierFlags modifier_flags);
diff --git a/dome_key_event_source_simulator/dome_key_event_source_simulator.m b/dome_key_event_source_simulator/dome_key_event_source_simulator.m
index ddc8b5a..c1fa3cc 100644
--- a/dome_key_event_source_simulator/dome_key_event_source_simulator.m
+++ b/dome_key_event_source_simulator/dome_key_event_source_simulator.m
@@ -11,3 +11,31 @@
@implementation dome_key_event_source_simulator
@end
+
+void dkess_press_key(int key, NSEventModifierFlags modifier_flags) {
+ NSEvent *event1 = [NSEvent otherEventWithType:NSSystemDefined
+ location:NSZeroPoint
+ modifierFlags:0xa00
+ timestamp:0.0
+ windowNumber:0
+ context:nil
+ subtype:NSScreenChangedEventType
+ data1:(NX_KEYTYPE_PLAY << 16) | (0xa << 8)
+ data2:-1];
+ CGEventRef cg_event1 = [event1 CGEvent];
+ CGEventPost(kCGHIDEventTap, cg_event1);
+ CFRelease(cg_event1);
+
+ NSEvent *event2 = [NSEvent otherEventWithType:NSSystemDefined
+ location:NSZeroPoint
+ modifierFlags:0xb00
+ timestamp:0.0
+ windowNumber:0
+ context:nil
+ subtype:NSScreenChangedEventType
+ data1:(NX_KEYTYPE_PLAY << 16) | (0xb << 8)
+ data2:-1];
+ CGEventRef cg_event2 = [event2 CGEvent];
+ CGEventPost(kCGHIDEventTap, cg_event2);
+ CFRelease(cg_event2);
+}