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

input problem

Started by hello_there Jun 15, 2002 at 10:43 PM 3 replies 450+ views
Original Post
hello_there
hello_there
i can''t get direct input to work. i''m using the input stuff from the book opengl game programming. i followed the way they did it but it didn''t work. can someone tell me what function i have to call and how i get it working.
____________How could hell be worse?
acraig
acraig
Need a lot more information. "Doesn''t work" is not much of an error report. What is the ''input stuff'' from the opengl book? How do you know it is not working? What are you testing? Mouse, keyboard, joystick.

Please try to be a little more descriptive.


--------
Andrew
hello_there
hello_there
ok i'm trying to get the keyboard to work. so when you press left the player goes left. when i press the left key nothing happens. i know the moveing player code is right because is work when i use windows messages. i'm using the InputSystem.h and InputSystem.cpp files from chapter 16. i was just wondering what function i have to use to get it working and how to use them.

[edited by - hello_there on June 15, 2002 12:16:49 AM]
____________How could hell be worse?
uNiQue0815
uNiQue0815
oh... really... that''s one hell of a bad description

did you call the InputDevice->Acquire(); function ? do your procs return error codes ? you should always check for error-codes after DirectX function calls !

i''ll give you some code of my keyboard functions. it''s not the complete include, but i think it''s all you''ll need to write your own.
i''m not in the mood to rewrite somehow, so i''ll just post the functions. they''re for directx and winmessage (whenever directx doesn''t work or isn''t wanted...)

first, the initialization :

bool nexKeyboard::Init()
{
if (!hWnd) return FALSE;

HINSTANCE hInstance;

if (useDirectX)
{
hInstance = GetModuleHandle (NULL);
if (!diInterface) // if object was created as a stand-alone-object, diInterface has to be initialized
{ // if object was created by a nexInput-object, diInterface is already set
ErrorID = (long int) DirectInputCreate(hInstance, DIRECTINPUT_VERSION, &diInterface, NULL);
StandAlone = TRUE;
}

ErrorID = (long int)diInterface->CreateDevice (GUID_SysKeyboard, &Interface, NULL);
if (ErrorID != DI_OK)
{
useDirectX = FALSE;
}

if (useDirectX)
{
Interface->SetCooperativeLevel (hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
Interface->SetDataFormat(&c_dfDIKeyboard);

DIPROPDWORD propdw;
propdw.diph.dwSize = sizeof (DIPROPDWORD);
propdw.diph.dwHeaderSize = sizeof (DIPROPHEADER);
propdw.diph.dwObj = 0;
propdw.diph.dwHow = DIPH_DEVICE;
propdw.dwData = Config.BufferSize;
Interface->SetProperty (DIPROP_BUFFERSIZE, &propdw.diph);

Interface->Acquire();
}
else
{
}
}
else
{
}

KeyBuffer = (char*)malloc (Config.BufferSize);
for (long int x=0; x<256; x++)
{
KeyState[x] = 0;
}

isInitialized = TRUE;

return TRUE;
}

KeyState is an array of 256 chars. here the keyboard-state will be stored (which keys are pressed or not...)

then the update function, which should be called periodicly :

bool nexKeyboard::Update()
{
if (!isInitialized) return FALSE;
if (!useDirectX) return TRUE; // if DirectX is not used, nothing''s to do here...

ErrorID = (long int)Interface->GetDeviceState(256, &KeyState);

if (ErrorID != DI_OK)
{
switch (ErrorID)
{
case DIERR_INPUTLOST:
case DIERR_NOTACQUIRED:
{
Interface->Acquire();
break;
}
}
}

DWORD traffic;
traffic = 1;
char c;
ErrorID = (long int)Interface->GetDeviceData (sizeof(newData), &newData, &traffic, 0);
if (traffic)
{
if (newData.dwData & 0x80)
{
c = DIK_KeyList[newData.dwOfs][0];
if (c != ''\0'') EnqueueKey (c);
}
}

return TRUE;
}


and the code for checking whether a key is pressed, or not...

bool nexKeyboard::KeyDown (unsigned char Key)
{
return ((KeyState[Key] & 0x80) != 0);
}



hope that''s enough to get your stuff working...
Mathematix
Mathematix
quote:
Original post by hello_there
i can''t get direct input to work. i''m using the input stuff from the book opengl game programming. i followed the way they did it but it didn''t work. can someone tell me what function i have to call and how i get it working.


OpenGL Game Programming is a very good book to learn the essentials of OpenGL from, but like any other language/API, you will need to take your time, study the examples and work on your own code from a blank sheet. That is what I am doing and I''m having ffew problems, apart from those teething ones!

Forgive me for preaching, but patience is required if your going to study the text.



Regards,
Mathematix.

Topic Locked

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

Sign in to reply to this topic.