使用 Xbox 360 控制器进行鼠标模拟
我正在编写一个小程序来用我的 Xbox 360 控制器模拟鼠标。我已经成功实现了光标的移动,但点击时遇到困难。
这是我的代码片段:
while (msg.message != WM_QUIT) {
if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
} else {
...
if (state.Gamepad.wButtons & XINPUT_GAMEPAD_A) {
PostMessage(HWND_BROADCAST, WM_LBUTTONDOWN, 0, MAKEWORD(new_x, new_y));
}
...
}
}
我不能 100% 确定这是正确的方法,但我尝试在 A< 时将 WM_LBUTTONDOWN
消息发送到所有顶级窗口/strong> 按钮被按下。但是,当我将鼠标放在一个按钮上并按 A 时,该按钮会闪烁,就像被单击一样,但随后什么也没有发生。
如果有人能指出我正确的方向或提供替代方法来做到这一点,我将非常感激!
I am writing a small program to emulate the mouse with my Xbox 360 controller. I have successfully implemented movement of the cursor but am having difficulty with clicks.
Here is a snippet of my code:
while (msg.message != WM_QUIT) {
if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
} else {
...
if (state.Gamepad.wButtons & XINPUT_GAMEPAD_A) {
PostMessage(HWND_BROADCAST, WM_LBUTTONDOWN, 0, MAKEWORD(new_x, new_y));
}
...
}
}
I'm not 100% sure this is the right approach but I'm trying to send the WM_LBUTTONDOWN
message to all top-level windows when the A button is pressed. But when I place the mouse over say, a button and press A, the button flashes as if it was clicked but then nothing happens.
If anyone can point me in the right direction or offer an alternative way to do this I'd be very grateful!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为,您宁愿使用 mouse_event API 甚至 发送输入。它允许您在更抽象的级别上综合鼠标事件。
I think, instead of PostMessage, you'd rather use the mouse_event API or even SendInput. It allows you to synthesise mouse events on a more abstract level.