Skip to main content
GameDev.net gamedev.net
🔒 Locked

directInput mouse and WASD can not function normally

Started by PixelCaption Jan 10, 2009 at 1:18 AM 6 replies 3.7k views
Original Post
PixelCaption
PixelCaption
hResult = pDevice->m_pDevice->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), data, &nEvents, 0 ); if( hResult != DI_OK ) { if( hResult == DI_BUFFEROVERFLOW ) { dsi_ConsolePrint ("Input buffer overflow on %s", pDevice->m_InstanceName); } else if (hResult == DIERR_INPUTLOST) { // Attempt to acquire it and retry .. maybe it got lost. hResult = pDevice->m_pDevice->Acquire(); hResult = pDevice->m_pDevice->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), data, &nEvents, 0 ); } } when i run this piece of code in the main input routine that reads input from all devices and sets any actions that are on,the mouse can not receive any response,however i can input username/password after i use tab, and i can use ENTER to assist for a login, and in the game lobby, all shortcut keys can be used except WASD and the mouse input, but it can input message after tabbing,so it can neither step backward/afterward/right/left, nor receive any mouse input. can anyone help me on this problem?
Evil Steve
Evil Steve
Quote:
Original post by PixelCaption
Can anyone help me on this problem?
Yes - don't use DirectInput. It's a terrible idea to use DirectInput for keyboard or mouse input; it requires a massive amount of effort, will annoy the hell out of your users (If you write an application that uses DirectInput for GUI mouse movement, it'll feel horribly wrong to the user in particular), means you can't use your app on any keyboard layout apart from English (So no way to run it on some European and Far East keyboard layouts), and is slower than using window messages.

If anyone recommends you using DirectInput for keyboard or mouse input, then they're wrong or an idiot.
PixelCaption
PixelCaption
however, the input device in the engine is written using DirectInput, though a bit out of state. i have researched a certain game engines, even commerical engines,finding that almost all input device in these engines is related with DirectInput,also if not using DirectInput, then will there be any other alternatives?
as for the question i mentioned above, it needs to check the state of DIERR_INPUTLOST, or it will crash, but if i check it, then the mouse input and keyboard input under some situation can not run normally, is it a regular loss of focus?
regards,
GameFissure
GameFissure
I didn't read everything but do as Evil Steve says... don't use DirectInput. Although it does contain support for a keyboard and mouse, it should mainly be used for other devices such as Gamepads. The reason is simple; DirectInput involves hooks, while APIs such as Win32 do not. The method?... well, either use Win32 or another API like MFC. If you do decide to use Win32 here's a few tutorials:

Mouse:
http://www.zeuscmd.com/tutorials/win32/08-MouseInput.php
http://www.tutcity.com/view/mouse-input-win32-api.17965.html

keyboard:
http://www.zeuscmd.com/tutorials/win32/07-KeyboardInput.php

I can't say if they are any good because I didn't exactly read much... sorry.

Fissure.
PixelCaption
PixelCaption
GameFissure, from your comment here, i can figure out sth: do you mean that i should turn to windows message using win32?
also if adopting this method, then how does it influence the function of input device in the engine, should i abolish the DirectInput in the engine, and use the related windows message in the logical layer?

Steve, is the way of using win32 API such as GetKeyBoardState/GetMouseState faster than using windows message? one of my colleague recommends win32 API.

regards,
Evil Steve
Evil Steve
Quote:
Original post by PixelCaption
Steve, is the way of using win32 API such as GetKeyBoardState/GetMouseState faster than using windows message? one of my colleague recommends win32 API.
Just use the window mnessages, WM_KEYDOWN, WM_MOUSEMOVE, etc. You should be processing all of your window messages once per frame, and getting state more than once per frame is going to be completely unnecessary - and could cause problems where you use one value for the mouse position at one point in the frame, and a different value at another point. There's no advantage to trying to get input at a rate of more than once per frame - and the window messages are being sent to your window anyway, meaning there's no overhead from using them.
GameFissure
GameFissure
Basically just learn Win32... based of your question that is what you need. Search 'C++ Win32 Tutorial' assuming your using C++.
Malazar
Malazar
Quote:
Original post by Evil Steve

If anyone recommends you using DirectInput for keyboard or mouse input, then they're wrong or an idiot.


Or one of my old university lecturers.

It's true, I was in exactly the same situation trying to get direct input to work, asked pretty much the same question on these forums, and have been using windows messages ever since, it's much better with those.

Topic Locked

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

Sign in to reply to this topic.