Reputation:
We have a 3D application that retrieves keyboard presses via the IDirectInputDevice8. Is there any way, when we retrive keyboard events via the win32 API winproc loop back that we can send these commands to the DirectInputDevice?
Upvotes: 1
Views: 2152
Reputation: 29401
Windows polls the keyboard hardware behind the scenes. When key events happen, it adds the respective WM_* messages to your Windows message queue (with associated information on keyboard state). The windows message pump pulls those messages off the queue and processes them accordingly. The main benefit of this approach is that you really don't have to do a lot to get hold of the keyboard events (plus knowledge of the keyboard layout/hardware isn't required). The disadvantage is that it really isn't real-time.
Talking to the Keyboard via DirectInput is actually similar, but it's up to you to do the polling. Usually, you use DirectInput to set up a keyboard device, and then every time you run your update loop, you poll the state of the keyboard using GetDeviceState(). It is up to you to keep track of the state of the keyboard between polls. The best thing to do is to create an object that wraps up this functionality, and perhaps fires events/callbacks or creates a command entry in a queue at the appropriate times so that it's nicer to work with. The advantage of this method is speed as you're talking to the hardware directly and can invoke updates instantly. The disadvantage is that you have to do this stuff manually which takes a bit of time to set up and get right.
Check out this example of how to use DirectInput to query the keyboard.
So there are a few answers to your question:
I hope that helps. Good luck!
Upvotes: 1
Reputation: 10560
The wndproc will is sent a combination of these messages on keyboard events:
WM_SYSKEYDOWN
WM_SYSKEYUP
WM_KEYDOWN
WM_KEYUP
WM_CHAR
Upvotes: 0