Skip to main content
GameDev.net gamedev.net
🔒 Locked

Query state of physical input devices using Winapi

Started by _Al3X_ Oct 11, 2025 at 3:05 PM 0 replies 850+ views
Original Post
_Al3X_
_Al3X_

I everyone, I'm currently working on the input management module of my own custom game engine.

My idea to handle input is to build two systems: the input system (enables the user to list all the input devices attached and poll their state) and the event system (enables the user to set listeners for input events, those gets invoked when update of the engine is called and the event queue gets flushed, once per frame).

Those two system should be completely separated, the user may use only one of them or both depending on his needs.

I'm using C++ and only low level APIs (Winapi on Windows and Xlib on Linux).

My problem is that using Winapi (raw input) I cannot read the state of input devices (i.e. a Keyboard) outside of wndProc, I have been able to list all the connected input devices but I cannot retrieve their state.

There are functions like getKeyboardState, but that does not differentiate between different physical keyboards.

Searching around I found this https://www.gamedev.net/forums/topic/700010-winapi-raw-input-confusion/ but windows forbids to open some device file descriptors (i.e. keyboard) in read shared mode; I can open the device fd without permission but then, when I try to use the Hid_* functions they will fail.

Is it possible to query the state of physical input devices using Winapi outside of the window procedure?

As I said getKeyboardState does not work for my needs, I read that direct input is deprecated and the HID library does not seem to work either due to fail in opening of the device file descriptor.

This seems to me the most flexible way to build a low level input system for my engine.

Is this possible? Am I missing something? I searched a lot, but found nothing :_(

If anyone can help, thanks in advance.

P.S. Any advice on the input module architecture itself is welcome too

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.