本文介绍了如何使用 winapi 的 SendInput 发送密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 winapi-rs 0.2.4 将本示例转换为 Rust 1.3.
I am trying to convert this example to Rust 1.3 with winapi-rs 0.2.4.
我有:
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);
}
}
不编译:
error: mismatched types:
expected `winapi::winuser::MOUSEINPUT`,
found `winapi::winuser::KEYBDINPUT`
(expected struct `winapi::winuser::MOUSEINPUT`,
found struct `winapi::winuser::KEYBDINPUT`) [E0308]
如何将击键发送到活动窗口?
Haw do I send keystrokes to the active window?
推荐答案
您使用的winapi-rs版本中winapi::INPUT
的定义有误.今天似乎已修复(或昨天,取决于您所在的位置).
The definition of winapi::INPUT
in the version of winapi-rs you use is incorrect. It appears to have been fixed today (or yesterday, depending on where you are).
这篇关于如何使用 winapi 的 SendInput 发送密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!