Can I use the Windows Raw Input API without a window (i.e. from a console application)?

Can I use the Windows Raw Input API without a window (i.e. from a console application)?

I tried to use RegisterRawInputDevices, but my message loops do not seem to receive any events from GetMessage and, therefore, are just there.

+4
source share
2 answers

Do you mean RegisterRawInputDevices ?

Since the RAWINPUTDEVICE structure requires an HWND to receive WM_INPUT messages, this cannot be done without a window.

Console applications can create windows, and the window may possibly receive WM_INPUT while it is hidden, but you need a window.

+2
source

So I did this (not sure if this is the most convenient way ...):

I started the thread (for the task of filling my input buffer). In this thread, I created a window for messages only (its hidden and can receive input data) with the corresponding class window.

Then the raw input devices registered.

This thread has its own message handler loop. In the WindowProc window class, I handled the inputs.

(For buffer, you can use boost: circle_buffer, it's ROCKS !: D)

In this solution, you needed a window, but it looks like you didn’t. :)

Hope this helps.

+6
source

All Articles