diff --git a/native/libmacbridge/bridge.h b/native/libmacbridge/bridge.h index 556c24c..d6ff506 100644 --- a/native/libmacbridge/bridge.h +++ b/native/libmacbridge/bridge.h @@ -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. */ diff --git a/native/libmacbridge/bridge.mm b/native/libmacbridge/bridge.mm index 6e74b96..90255bb 100644 --- a/native/libmacbridge/bridge.mm +++ b/native/libmacbridge/bridge.mm @@ -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); + }); } \ No newline at end of file diff --git a/src/keyboard/macos.rs b/src/keyboard/macos.rs index c3df31a..5e476ab 100644 --- a/src/keyboard/macos.rs +++ b/src/keyboard/macos.rs @@ -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); } \ No newline at end of file