English 中文(简体)
获取 Windows 上的鼠标光标定位和按钮状态
原标题:Getting mouse cursor position and button state on Windows

在 Windows( Windows 7 及以上) 上获取鼠标指针位置或按钮状态的最适当方式是什么? 我曾经使用过 DirectInput, 但我不再使用它, 也不愿使用它。 我看到有 GetCursorPos, 但是, 我看不出有什么可以获取鼠标按钮状态 。 我之前读过, 仅仅读过窗口信息( 如 WM_ LBUTTONUP) 被实时应用程序视为“ 慢速 ”, 因此我不知道其他选项 。

最佳回答

如果您想要对当前光标位置进行民意测验/查询, 您可以使用 < a href=" http://msdn. microsoft. com/ en- us/library/ windows/desktop/ ms648390%28v=vs. 85%29. aspx" rel=“ norefererr” >GetCursorPos 。 要查看按钮状态, 请使用 < a href=> http://msdn. microsoft. com/ en- us/library/ windows/desktop/ms646293% 28v=vs. 85% 29. aspx" rel=“ noreferr>GetAsyncKeystate 。

如果您在窗口中执行消息环绕, 您将获得的鼠标移动通知是 < a href=" http:// msdn. microsoft.com/ en- us/library/ windows/ desktop/ ms645616%28v=vs. 85%29. aspx" rel= “ norefererr" >WM_ MOSIEMOVE

问题回答

WM_LBUTTONUP 和任何窗口信息一样好,因为窗口游戏是伟大的,因为它只有在鼠标单击客户区域时才生成,以便您可以调整大小并自由移动窗口。

As an alternative to direct input, you can use raw inputs which take up some more code to initialize, but it s the best way to go with the mouse movement since WM_INPUT is generated when the physical mouse moves, not the cursor, so you can clip the cursor in the client area without worrying that the user may hit the side of the clip rect and the mouse movement messages won t be generated anymore. link





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签