Advertisement

Direct Input Problem

Started by January 10, 2000 03:53 PM
4 comments, last by :-) 25 years, 1 month ago
Hi. I´m making a multiplayer game for 4 persons on 1 keyboard. I use GetKeyDevice but it dosn´t work very well. When I press a key everything stopps. and it dosn´t work to press many buttons at the same time. Shoud I use a different fuction or...? /Izk
:-)
Im really not sure about your function calls. However most keyboards (or atleast only the ones ive used) only seem to recognize two keys at a time (with an exception of shift/other keys like it).

Also, where is this function, GetKeyDevice, defined (direct input, win32, etc?) I cannot seem to find it in any of my help manuals.

Hope you find answers,
Fungame
Advertisement
What you need to do is to buffer the keyboard input and deal with it from that point. Direct Input offers the option of buffered input you''ll just have to implement it (check the docs). This allows you to trap every single key hit into an buffer. You read in the key''s pressed from the buffer rather than directly from the keyboard so no key gets missed.
Joseph FernaldSoftware EngineerRed Storm Entertainment.------------------------The opinions expressed are that of the person postingand not that of Red Storm Entertainment.
I´ve tried that... but it didn´t work for me. I´m not sure that I did it right. Can u give an example how to call the fuction?
:-)
IDirectInput7 *pDI = NULL;
IDirectInputDevice7 *pKeyb = NULL;
DIPROPDWORD dipdw;
DIDEVICEOBJECTDATA od[16];
DWORD dwElements = 16;

// Initialize DirectInput and the keyboard device

DirectInputCreateEx(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput7, (LPVOID*)&pDI, NULL);
pDI->CreateDeviceEx(GUID_SysKeyboard, IID_IDirectInputDevice7, (LPVOID*)&pKeyb, NULL);
pKeyb->SetDataFormat(&c_dfDIKeyboard);
pKeyb->SetCooperativeLevel(hWnd, DISCL_FOREGROUND / DISCL_NONEXCLUSIVE);
dipdw.diph.dwSize = sizeof(dipdw);
dipdw.diph.dwHeaderSize = sizeof(dipdw.diph);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = dwElements;

// Set up for buffered device data

pKeyb->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph);
pKeyb->Acquire();
pKeyb->GetDeviceData(sizeof(od[0]), od, &dwElements, 0);

// After the GetDeviceData call dwElements contains the number of inputdata in the od array (0 - 15). If 0 don''t process anything

// Now check the buffer od for inputdata and process them
od.dwOfs[0 to 15] is one of the keyboard device constants like DIK_UP or DIK_DOWN

// If you are finished call this
pKeyb->Unacquire();
pKeyb->Release();
pDI->Release();
Thanks! I will try this.
:-)

This topic is closed to new replies.

Advertisement