Is it possible to use Windows Raw Input API without a window (ie from a console application)?

淺唱寂寞╮ 提交于 2019-12-01 22:23:33

问题


Is it possible to use Windows Raw Input API without a window (ie from a console application)?

I've tried using RegisterRawInputDevices but my message loops doesn't seem to get any events from GetMessage and hence just 'hangs' there.


回答1:


Do you mean RegisterRawInputDevices?

Since the RAWINPUTDEVICE structure requires you to specify an HWND to receive the WM_INPUT messages, no it's not possible to do this without a window.

Console applications can create windows, and the window probably can receive WM_INPUT while hidden, but you do need a window.




回答2:


That way I did it (not sure it is the most comfortable way...):

I have started a thread (for the task of filling my input buffer). In this thread I have created a message-only window (its hidden, and can get input datas) with an appropriate window-class.

Then registered the raw input devices.

This thread has its own message handler loop. In the WindowProc of the window-class I've handled the inputs.

(For buffer, You can use boost:circular_buffer, it ROCKS! :D)

In this solution You did need have a window, but it looks like You don't. :)

I hope this can help.



来源:https://stackoverflow.com/questions/6800982/is-it-possible-to-use-windows-raw-input-api-without-a-window-ie-from-a-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!