我試圖將this example轉換爲Rust 1.3,並且winapi-rs 0.2.4。如何使用winapi的SendInput發送密鑰?
我:
error: mismatched types:
expected `winapi::winuser::MOUSEINPUT`,
found `winapi::winuser::KEYBDINPUT`
(expected struct `winapi::winuser::MOUSEINPUT`,
found struct `winapi::winuser::KEYBDINPUT`) [E0308]
唧唧我發送擊鍵到活動窗口:
fn send_key_event(vk: u16, flags: u32) {
let mut input = winapi::INPUT {
type_: winapi::INPUT_KEYBOARD,
union_: winapi::KEYBDINPUT {
wVk: vk,
wScan: 0,
dwFlags: flags,
time: 0,
dwExtraInfo: 0,
}
};
unsafe {
user32::SendInput(1, &mut input, mem::size_of::<winapi::INPUT>() as i32);
}
}
不與編譯?
自動化UI的正確方法是[UI自動化](https://msdn.microsoft.com/en-us/library/windows/desktop/ee684009.aspx)。你正在嘗試的是一個脆弱的黑客。例如,如果指定的接收器不是前景窗口,它將失敗。另外,活動窗口是沒有關聯的。輸入進入前臺窗口。前景窗口恰好是前景線程的活動窗口。 – IInspectable
@IInspectable謝謝你的鏈接!你有沒有生鏽的例子? – Jacob