0

This question is part of a long story about trying to get input messages, WM_INPUT, from outside of the main window for an application.

The reason is that the main loop's frequency is lower than the desired frequencies for input processing. I don't have the choice to change the workload in the main loop itself, as other functionality needs to be performed in the main thread. I'm thus left with one choice - to manage input outside of the main thread.

Given the following factors:

  • Let's say that we have several message-only windows, running on different threads;
  • We are using the RawInput API to register and receive WM_INPUT messages for different input devices;
  • The different threads will share a few data structures to work together on input processing;

Is there a method to identify one WM_INPUT message sent to different threads as being the same message?

Is there a serial number, or a counter, or something to identify that messages that are sent from the same source at the same polling, to be used when comparing the input shared data between the threads?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Physician
  • 483
  • 2
  • 7
  • The only unique identifier available in WM_INPUT is the device HANDLE in the message's header. Why do you have multiple windows receiving input for the same device? – Remy Lebeau Mar 09 '23 at 15:29
  • @RemyLebeau In other input APIs of Windows, there is usually an integer that marks each message and keeps changing with each new message to let the application know that these messages are different. I need similar data in RawInput. The question is more about the details within the RawInput itself rather than the WM_INPUT message itself. As to why multiple windows, this is an attempt to get around context switching when the input processing thread is being halted from running temporarily. These are spare threads for continuing the same task. Do you think of any work around that? – Physician Mar 09 '23 at 15:46
  • @Phsician "*In other input APIs of Windows*" - such as? "*there is usually an integer that marks each message and keeps changing with each new message*" - I have never seen such a counter used in input messages. Can you provide an example? The only such counter I have ever seen the Win32 API expose is the [clipboard sequence counter](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getclipboardsequencenumber). "*I need similar data in RawInput*" - sorry, but there is no such data provided by the RawInput API. – Remy Lebeau Mar 09 '23 at 18:30
  • @RemyLebeau In XInput API, there is the XINPUT_STATE struct, with the field DWORD dwPacketNumber and it "indicates whether there have been any changes in the state of the controller. If the dwPacketNumber member is the same in sequentially returned XINPUT_STATE structures, the controller state has not changed". Then later in the remarks it adds "The dwPacketNumber member is incremented only if the status of the controller has changed since the controller was last polled" – Physician Mar 09 '23 at 20:23
  • @RemyLebeau If I understood correctly, then that is such a valuable piece of data that I wish was available in all Input APIs. – Physician Mar 09 '23 at 20:24

0 Answers0