GetKeyState 在 Windows 2000 (C++) 中不起作用

发布于 2024-09-28 07:16:34 字数 783 浏览 3 评论 0原文

我刚刚在 Windows 2000 SP4 系统上测试了我的 DirectX 游戏,但它不会收到任何鼠标点击!

这就是我检查鼠标点击的方式:

    unsigned int mButtons = 0;
    if (GetKeyState(VK_LBUTTON) < 0) mButtons |= HIDBoss::MOUSE_LEFT;
    if (GetKeyState(VK_RBUTTON) < 0) mButtons |= HIDBoss::MOUSE_RIGHT;
    if (GetKeyState(VK_MBUTTON) < 0) mButtons |= HIDBoss::MOUSE_MIDDLE;
    if (GetKeyState(VK_XBUTTON1) < 0) mButtons |= HIDBoss::MOUSE_4;
    if (GetKeyState(VK_XBUTTON2) < 0) mButtons |= HIDBoss::MOUSE_5;

等等...

此代码在 Windows 7 和 XP 32/64 位上完美运行。

如果我使用 OIS 库(它使用 DirectX 输入),问题就修复,但它包含一些错误,所以我宁愿避免它。

谁能建议为什么 GetKeyState 在 W2K 上不起作用?难道是因为系统在过去几年里没有通过 Windows Update 进行更新吗?

谢谢你的宝贵时间,

比尔

I have just tested my DirectX game on a Windows 2000 SP4 system but it won't receive any mouse clicks!

This is how I check for mouse clicks :

    unsigned int mButtons = 0;
    if (GetKeyState(VK_LBUTTON) < 0) mButtons |= HIDBoss::MOUSE_LEFT;
    if (GetKeyState(VK_RBUTTON) < 0) mButtons |= HIDBoss::MOUSE_RIGHT;
    if (GetKeyState(VK_MBUTTON) < 0) mButtons |= HIDBoss::MOUSE_MIDDLE;
    if (GetKeyState(VK_XBUTTON1) < 0) mButtons |= HIDBoss::MOUSE_4;
    if (GetKeyState(VK_XBUTTON2) < 0) mButtons |= HIDBoss::MOUSE_5;

etc...

This code works perfectly on Windows 7 and XP 32/64bit.

The problem is fixed if I use the OIS library instead - which uses DirectX input - but it contains a few bugs so I would rather avoid it.

Can anyone suggest why GetKeyState won't work on W2K? Could it be because the system hasn't been updated - through Windows Update - for the last couple of years..?

Thank you for your time,

Bill

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无人问我粥可暖 2024-10-05 07:16:34

我不确定为什么它不起作用,但我建议使用 GetAsyncKeyState 代替。

编辑:回复您的评论。这只是一个建议,但同样很容易通过调用来找出按钮是否被交换:

GetSystemMetrics(SM_SWAPBUTTON)

您的大问题源于这样一个事实:GetKeyState 不应该仅返回鼠标按钮的值,而只能返回键盘按钮的值。事实上,它确实可以在某些操作系统中工作,但您不应该在所有操作系统上都可以依赖它。

应用程序调用 GetKeyState
对键盘输入消息的响应。
该函数检索状态
输入消息时的键
生成。

值得注意的是,它特别提到了调用它来响应键盘输入消息(即 WM_KEY[UP/DOWN])。同样,也没有提到这应该适用于小鼠。因此,您最好只使用 GetAsyncKeyState...

I'm not sure why it doesn't work but I'd recommend using GetAsyncKeyState instead.

Edit: In answer to your comment. It is merely a suggestion but its, equally, pretty easy to find out if the buttons are swapped by calling:

GetSystemMetrics(SM_SWAPBUTTON)

Your big problem arises from the fact that GetKeyState is not supposed to return a value for mouse buttons only keyboard buttons. the fact it DOES work in some OSs is not something you are supposed to be able to rely on across all OSs.

An application calls GetKeyState in
response to a keyboard-input message.
This function retrieves the state of
the key when the input message was
generated.

Its worth noting that it makes specific mention of calling it in response to a keyboard-input message (ie WM_KEY[UP/DOWN]). Equally there is no mention that this should work for mice. As such you really are better off just using GetAsyncKeyState...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文