Add clipboard backend for MacOS. Fix #9
This commit is contained in:
parent
1c0266c793
commit
5bc8de2408
|
@ -44,6 +44,11 @@ void send_vkey(int32_t vk);
|
|||
*/
|
||||
void delete_string(int32_t count);
|
||||
|
||||
/*
|
||||
* Trigger normal paste ( Pressing CMD+V )
|
||||
*/
|
||||
void trigger_paste();
|
||||
|
||||
// SYSTEM
|
||||
|
||||
/*
|
||||
|
|
|
@ -99,6 +99,38 @@ void send_vkey(int32_t vk) {
|
|||
});
|
||||
}
|
||||
|
||||
void trigger_paste() {
|
||||
dispatch_async(dispatch_get_main_queue(), ^(void) {
|
||||
CGEventRef keydown;
|
||||
keydown = CGEventCreateKeyboardEvent(NULL, 0x37, true); // CMD
|
||||
CGEventPost(kCGHIDEventTap, keydown);
|
||||
CFRelease(keydown);
|
||||
|
||||
usleep(2000);
|
||||
|
||||
CGEventRef keydown2;
|
||||
keydown2 = CGEventCreateKeyboardEvent(NULL, 0x09, true); // V key
|
||||
CGEventPost(kCGHIDEventTap, keydown2);
|
||||
CFRelease(keydown2);
|
||||
|
||||
usleep(2000);
|
||||
|
||||
CGEventRef keyup;
|
||||
keyup = CGEventCreateKeyboardEvent(NULL, 0x09, false);
|
||||
CGEventPost(kCGHIDEventTap, keyup);
|
||||
CFRelease(keyup);
|
||||
|
||||
usleep(2000);
|
||||
|
||||
CGEventRef keyup2;
|
||||
keyup2 = CGEventCreateKeyboardEvent(NULL, 0x37, false); // CMD
|
||||
CGEventPost(kCGHIDEventTap, keyup2);
|
||||
CFRelease(keyup2);
|
||||
|
||||
usleep(2000);
|
||||
});
|
||||
}
|
||||
|
||||
int32_t get_active_app_bundle(char * buffer, int32_t size) {
|
||||
NSRunningApplication *frontApp = [[NSWorkspace sharedWorkspace] frontmostApplication];
|
||||
NSString *bundlePath = [frontApp bundleURL].path;
|
||||
|
|
|
@ -20,4 +20,5 @@ extern {
|
|||
pub fn send_string(string: *const c_char);
|
||||
pub fn send_vkey(vk: i32);
|
||||
pub fn delete_string(count: i32);
|
||||
pub fn trigger_paste();
|
||||
}
|
|
@ -44,7 +44,9 @@ impl super::KeyboardSender for MacKeyboardSender {
|
|||
}
|
||||
|
||||
fn trigger_paste(&self) {
|
||||
unimplemented!()
|
||||
unsafe {
|
||||
trigger_paste();
|
||||
}
|
||||
}
|
||||
|
||||
fn delete_string(&self, count: i32) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user