Skip to main content
gamedev.net
🔒 Locked

Why do i need DirectInput??

Started by wannabe H4x0r Feb 23, 2003 at 2:19 AM 9 replies 500+ views
Original Post
wannabe H4x0r
wannabe H4x0r
simple question: why do should i even use directinput when i can use win api? im trying to make an RTS and i dont really need anything but basic mouse and keyboard functionality
RhoneRanger
RhoneRanger
It is really your choice.

Here are a few reasons why I use DirectInput

1. Eliminate the MsgProc
2. Eliminate the annoying MicroSoft key repeat
3. Give my application total control over the Keyboard and Mouse
4. Major performance boost! If you dont have to go through the message loop for Windows, and avoid the GetMessage (or PeekMessage) functions, you can dramatically increase performance!


But a better question is, why wouldn''t you use Direct Input?

Most games (dx) use only keyboard and mouse, but they all use DirectInput

Techlead
www.myran.com/enilno
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
Endurion
Endurion
For standard keyboard and mouse and even joystick input you can get away with the win32 api pretty good.

But what about extra game devices? Gamepads or joysticks with extra throttles and gears and more than the standard two axes?
You''ll need DirectInput for those.

Regards,
Endurion
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>
RhoneRanger
RhoneRanger
quote:
Original post by Anonymous Poster
Eliminating the message proc is a BAD_IDEA (tm)

There are some useful systemwide messages that you definitely want to be able to respond to, such as power-is-running-out on laptops and user-is-turning-off-computer..





I eliminate the message loop alltogether, but you do have a valid point.

I just assume that most people playing games are not going to turn off their computer in the middle of it, and if they are playing a game on a laptop, they can see if their battery is going low or not.

I still stick to the school to not use the message loop (GetMessage and PeekMessage) at all, although it is not that expensive, it (imho) is more efficient code to let DirectInput take care of all messages.

Techlead
www.myran.com/enilno
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
wannabe H4x0r
wannabe H4x0r
thanks but i''ve still got some questions here.

if i do eliminate the winproc, how do i keep windows functionality like alt-tab etc.

and also it seems that at least win api mouse routines run on a different thread (the mouse moves and renders it seems independent of anything else that''s going on in the program) i''m hardpressed to find a way to do this w/ directinput manually.

and about windows keyrepeat, if you hold down a key does it actually trigger repeated messages, and what message would that be??

p.s. i''m not really considering any control pads or joysticks or rumble packs for the RTS here, imagine your mouse starting to shake like insane in the middle of a bigass battle; i''m just sticking to old school mouse n keyboard here
thedo
thedo
I find that GetAsyncKeyState is very good for keyboard input, and GetCursorPos/SetCursorPos is pretty good for my mouse stuff. But thats just me. I''ve used DI and wasnt impressed. That said it is probably the best way to use force feedback peripherals (not much use to an RTS tho)

Neil

WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!
WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!
JonW
JonW
I''ve used GetAsnycKeyState in the past, but I found for some reason that when my game starts up GetAsyncKeyState sometimes tells me that the Enter key is down, even if I haven''t pressed it. Maybe another program didn''t respond to the message before the game started, but I would think that Windows would not give a program messages that occured before the program started.

But anyway, I''ve used DirectInput ever since then, and it works just fine for me.
wannabe H4x0r
wannabe H4x0r
thanks all but i''m still wondering how one can use directinput w/o input lag, i.e. game is running an update cycle that happens to be slow and you don''t want the mouse cursor or keyboard to be unresponsive
wannabe H4x0r
wannabe H4x0r
thanks all but i''m still wondering how one can use directinput w/o input lag, i.e. game is running an update cycle that happens to be slow and you don''t want the mouse cursor or keyboard to be unresponsive

Topic Locked

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

Sign in to reply to this topic.