Jump to content
  • Advertisement

Archived

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

zacharya

Direct Input

This topic is 5529 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
DI has a built in method to detect if any input has occured, IIRC you capture the GetDeviceState in an HR and it will return something like a D3D_NOINPUT constant , so consult the docs for the actual implementation and then just test for that.


Dredd

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!