Add passive mode Windows implementation

This commit is contained in:
Federico Terzi 2020-01-21 00:22:22 +01:00
parent 6e03e7e8e4
commit 6135787eb0
6 changed files with 46 additions and 19 deletions

View File

@ -524,6 +524,31 @@ void trigger_paste() {
SendInput(vec.size(), vec.data(), sizeof(INPUT)); SendInput(vec.size(), vec.data(), sizeof(INPUT));
} }
void trigger_copy() {
std::vector<INPUT> vec;
INPUT input = { 0 };
input.type = INPUT_KEYBOARD;
input.ki.wScan = 0;
input.ki.time = 0;
input.ki.dwExtraInfo = 0;
input.ki.wVk = VK_CONTROL;
input.ki.dwFlags = 0; // 0 for key press
vec.push_back(input);
input.ki.wVk = 0x43; // C KEY
vec.push_back(input);
input.ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
vec.push_back(input);
input.ki.wVk = VK_CONTROL;
vec.push_back(input);
SendInput(vec.size(), vec.data(), sizeof(INPUT));
}
// SYSTEM // SYSTEM
@ -699,3 +724,4 @@ int32_t set_clipboard_image(wchar_t *path) {
return result; return result;
} }

View File

@ -79,6 +79,11 @@ extern "C" void delete_string(int32_t count);
*/ */
extern "C" void trigger_paste(); extern "C" void trigger_paste();
/*
* Send the copy keyboard shortcut (CTRL+C)
*/
extern "C" void trigger_copy();
// Detect current application commands // Detect current application commands
/* /*

View File

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

View File

@ -62,6 +62,7 @@ impl super::Extension for ScriptExtension {
.output() .output()
}; };
println!("{:?}", output);
match output { match output {
Ok(output) => { Ok(output) => {
let output_str = String::from_utf8_lossy(output.stdout.as_slice()); let output_str = String::from_utf8_lossy(output.stdout.as_slice());
@ -86,6 +87,7 @@ mod tests {
use crate::extension::Extension; use crate::extension::Extension;
#[test] #[test]
#[cfg(not(target_os = "windows"))]
fn test_script_basic() { fn test_script_basic() {
let mut params = Mapping::new(); let mut params = Mapping::new();
params.insert(Value::from("args"), Value::from(vec!["echo", "hello world"])); params.insert(Value::from("args"), Value::from(vec!["echo", "hello world"]));
@ -94,15 +96,11 @@ mod tests {
let output = extension.calculate(&params, &vec![]); let output = extension.calculate(&params, &vec![]);
assert!(output.is_some()); assert!(output.is_some());
assert_eq!(output.unwrap(), "hello world\n");
if cfg!(target_os = "windows") {
assert_eq!(output.unwrap(), "hello world\r\n");
}else{
assert_eq!(output.unwrap(), "hello world\n");
}
} }
#[test] #[test]
#[cfg(not(target_os = "windows"))]
fn test_script_inject_args_off() { fn test_script_inject_args_off() {
let mut params = Mapping::new(); let mut params = Mapping::new();
params.insert(Value::from("args"), Value::from(vec!["echo", "hello world"])); params.insert(Value::from("args"), Value::from(vec!["echo", "hello world"]));
@ -111,15 +109,11 @@ mod tests {
let output = extension.calculate(&params, &vec!["jon".to_owned()]); let output = extension.calculate(&params, &vec!["jon".to_owned()]);
assert!(output.is_some()); assert!(output.is_some());
assert_eq!(output.unwrap(), "hello world\n");
if cfg!(target_os = "windows") {
assert_eq!(output.unwrap(), "hello world\r\n");
}else{
assert_eq!(output.unwrap(), "hello world\n");
}
} }
#[test] #[test]
#[cfg(not(target_os = "windows"))]
fn test_script_inject_args_on() { fn test_script_inject_args_on() {
let mut params = Mapping::new(); let mut params = Mapping::new();
params.insert(Value::from("args"), Value::from(vec!["echo", "hello world"])); params.insert(Value::from("args"), Value::from(vec!["echo", "hello world"]));
@ -129,11 +123,6 @@ mod tests {
let output = extension.calculate(&params, &vec!["jon".to_owned()]); let output = extension.calculate(&params, &vec!["jon".to_owned()]);
assert!(output.is_some()); assert!(output.is_some());
assert_eq!(output.unwrap(), "hello world jon\n");
if cfg!(target_os = "windows") {
assert_eq!(output.unwrap(), "hello world jon\r\n");
}else{
assert_eq!(output.unwrap(), "hello world jon\n");
}
} }
} }

View File

@ -24,7 +24,7 @@ use regex::{Regex, Captures};
lazy_static! { lazy_static! {
static ref POS_ARG_REGEX: Regex = if cfg!(target_os = "windows") { static ref POS_ARG_REGEX: Regex = if cfg!(target_os = "windows") {
Regex::new("\\%(?P<pos>\\d+)").unwrap() Regex::new("%(?P<pos>\\d+)").unwrap()
}else{ }else{
Regex::new("\\$(?P<pos>\\d+)").unwrap() Regex::new("\\$(?P<pos>\\d+)").unwrap()
}; };

View File

@ -73,4 +73,10 @@ impl super::KeyboardManager for WindowsKeyboardManager {
send_multi_vkey(0x25, count) send_multi_vkey(0x25, count)
} }
} }
fn trigger_copy(&self) {
unsafe {
trigger_copy();
}
}
} }