Archived

This topic is now archived and is closed to further replies.

zacharya

Direct Input

Recommended Posts

I have learnt that to detect a specific key pressed on keyboard I can use DIK_ but what if I want to detect is my keyboard is being pressed (any key) just like kbhit() function in dos mode thanks before

Share this post


Link to post
Share on other sites
You don''t need to use DirectInput for that if you are just looking to detect a single key press once. Just use a combination of WM_CHAR and WM_KEYDOWN.

If you need really need to use direct input, like if you need to worry about doing stuff while the key is down, then you can or all the DIK_* keys together and check for that...:

#define ALL_KEYS (DIK_A | DIK_B | DIK_C)

if (KEYDOWN(ALL_KEYS))


Hope this helps,
/jk

Share this post


Link to post
Share on other sites
You need to use buffered input with your DirectInput device(s). When you want to know if any key has been pressed, call GetDeviceData(). On return, if the DWORD pointed to by pdwInOut is 0, then the keyboard has not been hit yet. If it''s not 0, the keyboard has been hit.

The method that was suggested by the above poster actually won''t work, as DIK_ constants are not bitfields. You cannot use bit-wise OR with them.

Share this post


Link to post
Share on other sites