简体   繁体   English

Windows C ++-需要想法-在同一应用程序/窗口中组合鼠标输入和原始输入

[英]Windows C++ - Need Ideas - Combining Mouse Input and Raw Input in the same app/window

I'll try to keep this as short as possible. 我会尽量保持简短。

I have an app that has worked for years with a single mouse input. 我有一个使用单一鼠标输入即可使用多年的应用程序。 I am looking to incorporate the ability for my users to use other forms of input, such as interactive projectors, touch devices, or pretty much anything that provides WM_INPUT messages when you register for them. 我希望为我的用户合并使用其他形式的输入的功能,例如交互式投影仪,触摸设备或几乎所有在您注册时提供WM_INPUT消息的功能。

The general idea I had was I would have a list of Vendor IDs and/or Product IDs that I would handle with Raw Input (which provides VID/PID, device handle and other information) for each message (WM_INPUT) received. 我的一般想法是,对于收到的每条消息(WM_INPUT),我将使用原始输入(提供VID / PID,设备处理和其他信息)来处理供应商ID和/或产品ID的列表。 Any devices that are not handled in the Raw Input code would be handled in the Mouse Input code (WM_MOUSEMOVE, WM_LBUTTONDOWN, WM_RBUTTONDOWN, etc). 原始输入代码中未处理的任何设备都将在鼠标输入代码中处理(WM_MOUSEMOVE,WM_LBUTTONDOWN,WM_RBUTTONDOWN等)。

Ideally, I would be able to leave all of my Mouse Input code as is, or close to it. 理想情况下,我可以将所有的“鼠标输入”代码保留为原样,也可以保持接近。 This way, if a user plugs in two mice, or a mouse and an unsupported pointing device (meaning my Raw Input code doesn't handle it based on VID/PID) the devices would both use the same system cursor. 这样,如果用户插入了两只鼠标,或者一只鼠标和一个不受支持的定点设备(这意味着我的原始输入代码无法根据VID / PID处理它),则这些设备都将使用相同的系统光标。 Any device that is known by my Raw Input code would be given separate cursors that exist only within my app. 我的原始输入代码可识别的任何设备都将获得单独的游标,这些游标仅存在于我的应用程序中。

The problem is simple: Mouse Input does not provide any information about the source of the message (such as WM_MOUSEMOVE, etc). 问题很简单:鼠标输入不提供有关消息来源的任何信息(例如WM_MOUSEMOVE等)。 Knowing that the message originated from touch helps (I have this implemented) but is definitely not enough. 知道消息来自触摸是有帮助的(我已经实现了此功能),但绝对不够。 I need some kind of unique identifier. 我需要某种唯一标识符。 If I could know the source of the Mouse Input, I could only handle Mouse Input from devices that aren't on my list of known devices, and I could only handle Raw Input that are on my list of known devices. 如果我能知道鼠标输入的来源,那么我只能处理不在已知设备列表中的设备的鼠标输入,并且只能处理已知设备列表中的原始输入。

Unfortunately, I cannot seem to find a way to achieve this. 不幸的是,我似乎找不到实现这一目标的方法。

Any ideas? 有任何想法吗?

Thanks for your time sorry for the lengthy post. 感谢您的宝贵时间,对于冗长的帖子,我们深表歉意。

TL;DR - Can you identify the source of Mouse Input (not Raw Input) in Windows? TL; DR-您可以识别Windows中鼠标输入(不是原始输入)的来源吗? Determining whether or not the source is touch is not enough information, I need some kind of unique identifier. 确定来源是否为触摸信息还不够,我需要某种唯一的标识符。

Mouse Input - http://msdn.microsoft.com/en-us/library/windows/desktop/ff468877(v=vs.85).aspx 鼠标输入-http: //msdn.microsoft.com/zh-cn/library/windows/desktop/ff468877(v=vs.85).aspx

Raw Input - http://msdn.microsoft.com/en-us/library/windows/desktop/ms645536(v=vs.85).aspx 原始输入-http: //msdn.microsoft.com/zh-cn/library/windows/desktop/ms645536(v=vs.85).aspx

I don't know of any API for getting some sort of device id after the fact. 我不知道有任何API可以在事后获取某种设备ID。

You could use the fact that WM_INPUT messages come before all other input messages, and when you handle WM_INPUT you could use GetRawInputDeviceInfo and a hash of the name returned by RIDI_DEVICENAME to use as a unique id. 您可以使用以下事实: WM_INPUT消息WM_INPUT所有其他输入消息之前,并且当您处理WM_INPUT ,可以使用GetRawInputDeviceInfoRIDI_DEVICENAME返回的名称的哈希作为唯一ID。 Or, you might be able to use the hDevice member of the RAWINPUTHEADER structure. 或者,您也许可以使用RAWINPUTHEADER结构的hDevice成员。

edit2: The answer to this question is "Not possible", you can't do it. edit2:这个问题的答案是“不可能”,您不能这样做。 Don't bother trying, but if you do and I'm wrong please explain. 不要费力尝试,但是如果您这样做并且我错了,请解释。 The fact of the matter is you can't rely on Windows to provide messages in any particular order consistently, which is what I was attempting to do. 事实是,您不能依靠Windows始终如一地以任何特定顺序提供消息,而这正是我试图做到的。 This bit me big time. 这让我很开心。 Either use raw input (WM_INPUT) or use mouse messages (wm_ mouse ) don't try to combine the two somehow. 使用原始输入(WM_INPUT)或使用鼠标消息(wm_ mouse )都不要尝试将两者结合。

I never really got the answer I wanted, but I got something that works so I thought it was worth sharing. 我从未真正得到想要的答案,但是我得到了一些可行的方法,因此我认为值得分享。

I am working on a huge assumption, as I can't find any documentation from Windows to support this assumption (and probably wouldn't really even trust it if I found documentation from windows). 我正在做一个巨大的假设,因为我找不到Windows提供的任何文档来支持这个假设(如果我从Windows找到文档,甚至可能根本不信任它)。 To my understanding, when a mouse event is generated at the lowest level it comes through the system as a raw input message first (WM_INPUT). 据我了解,当鼠标事件在最低级别生成时,它首先作为原始输入消息(WM_INPUT)通过系统。 After the WM_INPUT message is posted, the OS gets the message and applies the ballistics and whatever else it does before a WM_*MOUSE* message is posted. 在发布WM_INPUT消息之后,操作系统将获取该消息并应用弹道学以及在发布WM_ * MOUSE *消息之前进行的其他操作。 The huge assumption is that this process is serial in that it is always 1 WM_INPUT message followed by 1 WM_*MOUSE* message in the queue. 巨大的假设是此过程是串行的,因为它在队列中始终是1个WM_INPUT消息,后跟1个WM_ * MOUSE *消息。

With this assumption I am working with the following: When an input message is received, store all relevant information about the source device as the "current input information" When a mouse message is received, process it using the "current input information" as the source of the mouse message 在这种假设下,我正在以下工作:收到输入消息时,将与源设备有关的所有相关信息存储为“当前输入信息”。收到鼠标消息时,将“当前输入信息”用作消息。鼠标消息的来源

This allows me to use n inputs in my application independently. 这使我可以在应用程序中独立使用n个输入。

I'd also like to add that per Brandon's suggestion I am using the hDevice member of the RAWINPUTHEADER structure to uniquely identify each input. 我还要根据布兰登的建议添加我正在使用RAWINPUTHEADER结构的hDevice成员唯一标识每个输入。 Since a unique device can have multiple inputs, I have yet to come up with a good way of uniquely identifying each device. 由于一个唯一的设备可以有多个输入,因此我还没有想出一种唯一标识每个设备的好方法。 VID/PID doesn't work because you can have 2 of the exact same device with multiple inputs each plugged in. I'm still working on this, see Windows HID Device Name Format VID / PID不起作用,因为您可以拥有2个完全相同的设备,每个设备都插入了多个输入。我仍在处理此问题,请参阅Windows HID设备名称格式

Please let me know if anyone would like me to elaborate! 如果有人要我详细说明,请告诉我!

edit: not marking this as the answer since I believe the correct answer is "Not possible" 编辑:不将其标记为答案,因为我认为正确的答案是“不可能”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM