Add newline support on MacOS
This commit is contained in:
parent
072d883583
commit
3479c9a709
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -63,3 +63,21 @@ void delete_string(int32_t count) {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user