Add clipboard backend for MacOS. Fix #9

This commit is contained in:
Federico Terzi 2019-09-09 17:03:59 +02:00
parent 1c0266c793
commit 5bc8de2408
4 changed files with 41 additions and 1 deletions

View File

@ -44,6 +44,11 @@ void send_vkey(int32_t vk);
*/ */
void delete_string(int32_t count); void delete_string(int32_t count);
/*
* Trigger normal paste ( Pressing CMD+V )
*/
void trigger_paste();
// SYSTEM // SYSTEM
/* /*

View File

@ -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) { int32_t get_active_app_bundle(char * buffer, int32_t size) {
NSRunningApplication *frontApp = [[NSWorkspace sharedWorkspace] frontmostApplication]; NSRunningApplication *frontApp = [[NSWorkspace sharedWorkspace] frontmostApplication];
NSString *bundlePath = [frontApp bundleURL].path; NSString *bundlePath = [frontApp bundleURL].path;

View File

@ -20,4 +20,5 @@ extern {
pub fn send_string(string: *const c_char); pub fn send_string(string: *const c_char);
pub fn send_vkey(vk: i32); pub fn send_vkey(vk: i32);
pub fn delete_string(count: i32); pub fn delete_string(count: i32);
pub fn trigger_paste();
} }

View File

@ -44,7 +44,9 @@ impl super::KeyboardSender for MacKeyboardSender {
} }
fn trigger_paste(&self) { fn trigger_paste(&self) {
unimplemented!() unsafe {
trigger_paste();
}
} }
fn delete_string(&self, count: i32) { fn delete_string(&self, count: i32) {