Add newline support on MacOS

This commit is contained in:
Federico Terzi 2019-09-06 10:49:05 +02:00
parent 072d883583
commit 3479c9a709
3 changed files with 31 additions and 0 deletions

View File

@ -34,6 +34,11 @@ void register_keypress_callback(void *self, KeypressCallback callback);
*/
void send_string(const char * string);
/*
* Send the Virtual Key press
*/
void send_vkey(int32_t vk);
/*
* Send the backspace keypress, *count* times.
*/

View File

@ -62,4 +62,22 @@ void delete_string(int32_t count) {
usleep(2000);
}
});
}
void send_vkey(int32_t vk) {
dispatch_async(dispatch_get_main_queue(), ^(void) {
CGEventRef keydown;
keydown = CGEventCreateKeyboardEvent(NULL, vk, true);
CGEventPost(kCGHIDEventTap, keydown);
CFRelease(keydown);
usleep(2000);
CGEventRef keyup;
keyup = CGEventCreateKeyboardEvent(NULL, vk, false);
CGEventPost(kCGHIDEventTap, keyup);
CFRelease(keyup);
usleep(2000);
});
}

View File

@ -34,6 +34,13 @@ impl super::KeyboardSender for MacKeyboardSender {
}
}
fn send_enter(&self) {
unsafe {
// Send the kVK_Return key press
send_vkey(0x24);
}
}
fn delete_string(&self, count: i32) {
unsafe {delete_string(count)}
}
@ -79,5 +86,6 @@ extern {
fn initialize();
fn eventloop();
fn send_string(string: *const c_char);
fn send_vkey(vk: i32);
fn delete_string(count: i32);
}