diff --git a/native/libwinbridge/bridge.cpp b/native/libwinbridge/bridge.cpp index 7011d4b..75b0597 100644 --- a/native/libwinbridge/bridge.cpp +++ b/native/libwinbridge/bridge.cpp @@ -495,8 +495,12 @@ void send_string(const wchar_t * string) { /* * Send the backspace keypress, *count* times. */ -void delete_string(int32_t count) { - send_multi_vkey(VK_BACK, count); +void delete_string(int32_t count, int32_t delay) { + if (delay != 0) { + send_multi_vkey_with_delay(VK_BACK, count, delay); + }else{ + send_multi_vkey(VK_BACK, count); + } } void send_vkey(int32_t vk) { @@ -539,6 +543,27 @@ void send_multi_vkey(int32_t vk, int32_t count) { SendInput(vec.size(), vec.data(), sizeof(INPUT)); } +void send_multi_vkey_with_delay(int32_t vk, int32_t count, int32_t delay) { + for (int i = 0; i < count; i++) { + INPUT input = { 0 }; + + input.type = INPUT_KEYBOARD; + input.ki.wScan = 0; + input.ki.time = 0; + input.ki.dwExtraInfo = 0; + input.ki.wVk = vk; + input.ki.dwFlags = 0; // 0 for key press + SendInput(1, &input, sizeof(INPUT)); + + Sleep(delay); + + input.ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release + SendInput(1, &input, sizeof(INPUT)); + + Sleep(delay); + } +} + void trigger_paste() { std::vector vec; diff --git a/native/libwinbridge/bridge.h b/native/libwinbridge/bridge.h index bd07a78..e27c872 100644 --- a/native/libwinbridge/bridge.h +++ b/native/libwinbridge/bridge.h @@ -72,10 +72,15 @@ extern "C" void send_vkey(int32_t vk); */ extern "C" void send_multi_vkey(int32_t vk, int32_t count); +/* + * Send the given Virtual Key press multiple times adding a delay between each keypress + */ +extern "C" void send_multi_vkey_with_delay(int32_t vk, int32_t count, int32_t delay); + /* * Send the backspace keypress, *count* times. */ -extern "C" void delete_string(int32_t count); +extern "C" void delete_string(int32_t count, int32_t delay); /* * Send the Paste keyboard shortcut (CTRL+V) diff --git a/src/bridge/windows.rs b/src/bridge/windows.rs index 0513fd4..59ea5a7 100644 --- a/src/bridge/windows.rs +++ b/src/bridge/windows.rs @@ -57,7 +57,7 @@ extern { pub fn send_string(string: *const u16); pub fn send_vkey(vk: i32); pub fn send_multi_vkey(vk: i32, count: i32); - pub fn delete_string(count: i32); + pub fn delete_string(count: i32, delay: i32); pub fn trigger_paste(); pub fn trigger_copy(); } \ No newline at end of file diff --git a/src/config/mod.rs b/src/config/mod.rs index c308ce6..0acbaf7 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -62,6 +62,7 @@ fn default_passive_key() -> KeyModifier { KeyModifier::OFF } fn default_enable_passive() -> bool { false } fn default_enable_active() -> bool { true } fn default_backspace_limit() -> i32 { 3 } +fn default_backspace_delay() -> i32 { 0 } fn default_restore_clipboard_delay() -> i32 { 300 } fn default_exclude_default_entries() -> bool {false} fn default_secure_input_watcher_enabled() -> bool {true} @@ -168,6 +169,9 @@ pub struct Configs { #[serde(default = "default_fast_inject")] pub fast_inject: bool, + #[serde(default = "default_backspace_delay")] + pub backspace_delay: i32, + #[serde(default = "default_matches")] pub matches: Vec, diff --git a/src/keyboard/windows.rs b/src/keyboard/windows.rs index f8a9a61..e21f05d 100644 --- a/src/keyboard/windows.rs +++ b/src/keyboard/windows.rs @@ -62,9 +62,9 @@ impl super::KeyboardManager for WindowsKeyboardManager { } } - fn delete_string(&self, _: &Configs, count: i32) { + fn delete_string(&self, config: &Configs, count: i32) { unsafe { - delete_string(count) + delete_string(count, config.backspace_delay) } }