Add trigger_copy implementation on MacOS

This commit is contained in:
Federico Terzi 2020-01-22 21:51:36 +01:00
parent 6135787eb0
commit 86586623cc
4 changed files with 47 additions and 1 deletions

View File

@ -80,6 +80,11 @@ void delete_string(int32_t count);
*/
void trigger_paste();
/*
* Trigger normal copy ( Pressing CMD+C )
*/
void trigger_copy();
// UI
/*

View File

@ -180,6 +180,39 @@ void trigger_paste() {
});
}
void trigger_copy() {
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, 0x08, true); // C key
CGEventPost(kCGHIDEventTap, keydown2);
CFRelease(keydown2);
usleep(2000);
CGEventRef keyup;
keyup = CGEventCreateKeyboardEvent(NULL, 0x08, 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;
@ -291,4 +324,5 @@ int32_t prompt_accessibility() {
void open_settings_panel() {
NSString *urlString = @"x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility";
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:urlString]];
}
}

View File

@ -59,4 +59,5 @@ extern {
pub fn send_multi_vkey(vk: i32, count: i32);
pub fn delete_string(count: i32);
pub fn trigger_paste();
pub fn trigger_copy();
}

View File

@ -56,6 +56,12 @@ impl super::KeyboardManager for MacKeyboardManager {
}
}
fn trigger_copy(&self) {
unsafe {
trigger_copy();
}
}
fn delete_string(&self, count: i32) {
unsafe {delete_string(count)}
}