Different options to handle mouse and keyboard input in a game

拈花ヽ惹草 提交于 2019-12-11 04:35:11

问题


I've recently been getting into DirectX and along with that, game programming. I've started fleshing out my base of the program and now I'm looking to get into handling input. The way I have right now is through calling a function in my main loop which queries the mouse and keyboard using GetDeviceState (in a nutshell) and their respective arguments; however, after doing some more in depth reading into DirectInput, I've seen many people saying how DirectInput is NOT recommended for use anymore. Microsoft seems to agree too!

What I am looking for are other ways to go about doing this, along with discussion on the pros and cons about them (not necessary, but welcome. I can research)


回答1:


Just use GetMessage or PeekMessage, see should-i-use-directinput-or-windows-message-loop for an example.




回答2:


You can use the win32/windows API.

People of gamedev seem to agree: http://www.gamedev.net/community/forums/topic.asp?topic_id=511020




回答3:


For keyboard I usually use GetAsyncKeyState();. It says if key is pressed in the time of execution of this function.

But for mouse the best solution is to use DirectInput I think. Because windows monitors it's position and you don't have to.




回答4:


Its recommended to use "Raw Input" these days.



来源:https://stackoverflow.com/questions/2205621/different-options-to-handle-mouse-and-keyboard-input-in-a-game

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