Skip to main content
gamedev.net
🔒 Locked

Input errors

Started by BloodLust666 10 replies 2.5k views
Original Post
BloodLust666
BloodLust666
I'm using DX9 and i'm using DirectInput (DX8). It seems that when i lose focus of the window, everything with the input screws up... y's that?
[source language="c++"]
// every frame, this is called
bool cInputDevice::Read()
{
	HRESULT hr;
	short i;

	if(!m_pDIDevice)
		return cError::Write("cInputDevice::Read()1");

	for (;;)
	{
		// Poll
		hr = m_pDIDevice->Poll();

		// Read in state
		if(SUCCEEDED(hr = m_pDIDevice->GetDeviceState(
			256, (LPVOID)&m_State)))
			break;

		// Return on an unknown error  
		if(hr != DIERR_INPUTLOST && hr != DIERR_NOTACQUIRED)
			return cError::Write("cInputDevice::Read()2");

		// Reacquire and try again
		if(FAILED(hr = m_pDIDevice->Acquire()))
			return true;
	}


	for(i=0;i<256;i++) {
		if(!(m_State & 0x80))
			m_Locks = false;
	}

	return true;
}

and whenever i try to run the program and have focus on a different window, i always get the: if(hr != DIERR_INPUTLOST && hr != DIERR_NOTACQUIRED) return cError::Write("cInputDevice::Read()2"); error every frame.
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
BloodLust666
BloodLust666
someone told me that it also has to do with something like how i'm defining my keys??

#define KEY_RELEASED false
#define KEY_PRESSED true

#define KEY_UNLOCKED false
#define KEY_LOCKED true

#define KEY_ESC DIK_ESCAPE
#define KEY_ESCAPE DIK_ESCAPE

#define KEY_MINUS DIK_MINUS
#define KEY_EQUALS DIK_EQUALS

#define KEY_BACKSPACE DIK_BACK

#define KEY_TAB DIK_TAB

#define KEY_LBRACKET DIK_LBRACKET
#define KEY_RBRACKET DIK_RBRACKET

#define KEY_ENTER DIK_RETURN
#define KEY_RETURN DIK_RETURN

#define KEY_CTRL DIK_LCONTROL
#define KEY_LCTRL DIK_LCONTROL
#define KEY_RCTRL DIK_RCTRL

#define KEY_SHIFT DIK_LSHIFT
#define KEY_LSHIFT DIK_LSHIFT
#define KEY_RSHIFT DIK_RSHIFT

#define KEY_ALT DIK_LMENU
#define KEY_LALT DIK_LMENU
#define KEY_RALT DIK_RMENU

#define KEY_0 DIK_0
#define KEY_1 DIK_1
#define KEY_2 DIK_2
#define KEY_3 DIK_3
#define KEY_4 DIK_4
#define KEY_5 DIK_5
#define KEY_6 DIK_6
#define KEY_7 DIK_7
#define KEY_8 DIK_8
#define KEY_9 DIK_9

#define KEY_A DIK_A
#define KEY_B DIK_B
#define KEY_C DIK_C
#define KEY_D DIK_D
#define KEY_E DIK_E
#define KEY_F DIK_F
#define KEY_G DIK_G
#define KEY_H DIK_H
#define KEY_I DIK_I
#define KEY_J DIK_J
#define KEY_K DIK_K
#define KEY_L DIK_L
#define KEY_M DIK_M
#define KEY_N DIK_N
#define KEY_O DIK_O
#define KEY_P DIK_P
#define KEY_Q DIK_Q
#define KEY_R DIK_R
#define KEY_S DIK_S
#define KEY_T DIK_T
#define KEY_U DIK_U
#define KEY_V DIK_V
#define KEY_W DIK_W
#define KEY_X DIK_X
#define KEY_Y DIK_Y
#define KEY_Z DIK_Z

#define KEY_SEMICOLON DIK_SEMICOLON
#define KEY_APOSTROPHE DIK_APOSTROPHE

#define KEY_TILDE DIK_GRAVE
#define KEY_GRAVE DIK_GRAVE

#define KEY_BACKSLASH DIK_BACKSLASH

#define KEY_COMMA DIK_COMMA
#define KEY_PERIOD DIK_PERIOD
#define KEY_FORWARDSLASH DIK_SLASH
#define KEY_SLASH DIK_SLASH

#define KEY_SPACE DIK_SPACE

#define KEY_CAPSLOCK DIK_CAPITAL
#define KEY_CAPITAL DIK_CAPITAL

#define KEY_F1 DIK_F1
#define KEY_F2 DIK_F2
#define KEY_F3 DIK_F3
#define KEY_F4 DIK_F4
#define KEY_F5 DIK_F5
#define KEY_F6 DIK_F6
#define KEY_F7 DIK_F7
#define KEY_F8 DIK_F8
#define KEY_F9 DIK_F9
#define KEY_F10 DIK_F10
#define KEY_F11 DIK_F11
#define KEY_F12 DIK_F12

#define KEY_SYSRQ DIK_SYSRQ
#define KEY_SCROLLLOCK DIK_SCROLL
#define KEY_PAUSE DIK_PAUSE

#define KEY_NUMLOCK DIK_NUMLOCK
#define KEY_NUMPAD0 DIK_NUMPAD0
#define KEY_NUMPAD1 DIK_NUMPAD1
#define KEY_NUMPAD2 DIK_NUMPAD2
#define KEY_NUMPAD3 DIK_NUMPAD3
#define KEY_NUMPAD4 DIK_NUMPAD4
#define KEY_NUMPAD5 DIK_NUMPAD5
#define KEY_NUMPAD6 DIK_NUMPAD6
#define KEY_NUMPAD7 DIK_NUMPAD7
#define KEY_NUMPAD8 DIK_NUMPAD8
#define KEY_NUMPAD9 DIK_NUMPAD9
#define KEY_ADD DIK_ADD
#define KEY_SUBTRACT DIK_SUBTRACT
#define KEY_DIVIDE DIK_DEVICE
#define KEY_MULTIPLY DIK_MULTIPLY
#define KEY_DECIMAL DIK_DECIMAL
#define KEY_NUMPADENTER DIK_NUMPADENTER

#define KEY_INSERT DIK_INSERT
#define KEY_DELETE DIK_DELETE
#define KEY_HOME DIK_HOME
#define KEY_END DIK_END
#define KEY_PAGEUP DIK_PRIOR
#define KEY_PAGEDOWN DIK_NEXT

#define KEY_UP DIK_UP
#define KEY_DOWN DIK_DOWN
#define KEY_LEFT DIK_LEFT
#define KEY_RIGHT DIK_RIGHT

#define KEY_LWIN DIK_LWIN
#define KEY_RWIN DIK_RWIN
#define KEY_APPS DIK_APPS

b/c when i try to compile in release mode, none of the keys work...
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
BloodLust666
BloodLust666
i think i figured something out... (pretty obvious, and i didn't see it) apparently, i'm losing the device... how would i re-get the device back?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
ferr
ferr
Quote:
Original post by EvilKnuckles666
i think i figured something out... (pretty obvious, and i didn't see it) apparently, i'm losing the device... how would i re-get the device back?


myDevice->Acquire(); You seem to be using this in your code already

I'm having a similar problem except getting "E_ACCESSDENIED" on Acquire and "The access code is invalid" when trying to Poll().
BloodLust666
BloodLust666
using it already? that's the only time i'm using it...
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
ferr
ferr
Quote:
Original post by EvilKnuckles666
using it already? that's the only time i'm using it...


the instructions after the failure for:

if(hr != DIERR_INPUTLOST && hr != DIERR_NOTACQUIRED)

seems like you should change:

return cError::Write("cInputDevice::Read()2");

to:

myDevice->Acquire();


maybe even change it from an if statement to a while statement.
BloodLust666
BloodLust666
hmmm.. i'll try that, not at home though. anyone else wanna double verify that for me? or if there's anyother way as well?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
NovaCaine
NovaCaine
it sounds like you need to reaquire your device, not sure how joypads work with DirectInput. If all devices are similar i have something like this for both my keyboard and mouse devices

hr = m_pKeyboard->Acquire();while( hr == DIERR_INPUTLOST ) {    hr = m_pKeyboard->Acquire();}


this gets called everytime i poll the keyboard and get a failed result back from GetDeviceState().

not sure if this is good coding practice, but it works for me so far... :)

Will have a look into this if i get time, wnating to add joypad support to my D3D app...
BloodLust666
BloodLust666
ok, i changed my loop to:

do
{
// Poll
hr = m_pDIDevice->Poll();

// Read in state
if(SUCCEEDED(hr = m_pDIDevice->GetDeviceState(
BufferSizes[m_Type-1], (LPVOID)&m_State)))
break;

// Aquire
hr = m_pDIDevice->Acquire();
} while (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED);

but that still does help when i don't have focus when he program starts, nothing works...
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
NovaCaine
NovaCaine
hmmm, what cooperation levels did you set? you could try setting the levels to DISCL_BACKGROUND, this way you should be able to aquire the device reguardless of the application having focus.

[Edited by - NovaCaine on September 27, 2005 5:50:48 PM]
BloodLust666
BloodLust666
wow! actually, that worked now, putting it in background instead of foreground. thanks!
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
NovaCaine
NovaCaine
thats all good... enjoy your joypad support :D

Topic Locked

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

Sign in to reply to this topic.