My 2nd request for help with buffered input.

Started by
7 comments, last by Firemage 22 years, 2 months ago
Hey there.. I posted this question once and received a rather unhelpful reply. I am trying to use DirectInput to buffer input fro the keyboard.. I went through all the contortions to make the buffer size 10. I can even retrieve data just fine.. I am just looking for a way to check to see if there is legitamate data to get. I have seen a bit masking operation like this: DIDEVICEOBJECTDATA buffer[10]; : : : if (buffer[x].dwData & 0x80){ : : : } it seems to me that that should check to see if a key has been pressed, but the condition inside the if () always evaluates to true for some reason. Anybody know what is going on? Do I need to post more code? Somebody please help me out here. I could get around this by cheating, but I will never learn if I skip something just becaue it challenges me. Thanks in advance, T.J. "Firemage" Martin To Thine own self be true No day but Today
To Thine own self be trueNo day but Today
Advertisement
The buffer needs to be 256 not 10.

DirectInput maps each key on the keyboard plus a lot of extras (for foreign keyboards) to a unique number not equal to the ASCII value.

To find what key is what number look in dinput.h

You can modify the definitions if you want.

  void Process_DirectInput(){	// Obtain input from the keyboard    if (pKeyboard->GetDeviceState(sizeof(keyBuffer),(LPVOID)&keyBuffer)        == DIERR_INPUTLOST)    {        // Reacquire the keyboard and try again        if (pKeyboard->Acquire() == DI_OK)            pKeyboard->GetDeviceState(sizeof(keyBuffer),(LPVOID)&keyBuffer);    }.........}  


where keyBuffer is your buffer but size 256 instead of 10.

That code must be called before you check the state of any keys.

Ben
http://therabbithole.redback.inficad.com


Umm.. that''d be immediate input.. I can do all that... I am looking for buffered input.. seems no one uses it.. but it''s there, dammit. And I want to learn it.

To Thine own self be true

No day but Today
To Thine own self be trueNo day but Today
Firemage Ive used buffered input before in a engine I made using diretx 7 , I dont have any code to tell you right now cause im at work, but ill see if I cant dig up the code for buffered input.
Ok here is the code I was talking about, this is how I implemented buffered input a little messy and im sure you can find a cleaner way to do it, but mine was just for a menu system so it didnt need to be elegant.

  LPDIRECTINPUTDEVICE Keyboard; define# DINPUT_BUFFERSIZE 32DIDEVICEOBJECTDATA rgod[DINPUT_BUFFERSIZE]; // Receives buffered dataDWORD   cod;cod = DINPUT_BUFFERSIZE;Keyboard->GetDeviceData( sizeof(DIDEVICEOBJECTDATA),rgod, &cod, 0);for( DWORD iod=0; iod<cod; iod++ ){if (rgod[iod].dwOfs == DIK_UP && rgod[iod].dwData & 0x80){do whatver}  


Basiclly you just use a loop to recieve from data from the buffer, and then I hardcoded my tests in the loop... which is the not so clean thing but it works.

Hope this helps you out some.

gerr this forum missed up the formatting




Edited by - zenroth on July 26, 2001 9:52:49 PM

Edited by - zenroth on July 31, 2001 4:36:46 PM
if your looking for what Key was pressed it''s in the dwOfs member of the DIDEVICEOBJECTDATA

DWORD Key = buffer[x].dwOfs;
switch(Key)
{
case DIK_ESCAPE:
return;
case DIK_UP:
MovePlayerUp();
break;
}
okay okay.. I am obviously not asking the right questions here...

I want to do buffered input the "correct" way... by checkig to see if somethig enetered the buffer... I don''t want to know what it is until I know it is there.. I can do that... I just want to know how to see if there is input.. everything I see says that you do this by checking the high bit f the low byte of .dwData. But this bit is always set for some reason.. why?

Pleeeease help me.. It''s driving me insane..

Thanx,

T.J.

To Thine own self be true

No day but Today
To Thine own self be trueNo day but Today
Hmmm I havent ever seen a example that checked, if the buffer had data in it before just reading and processing it.
About like winsock data for recieving, ive never known a way to really check and then process.

Are you basiclly just trying to test to see if there is data first before going and reading it? Kinda like peekmessage in the winapi?

I think any type of function like peek msg is going to have to loop through all the data or should I say a empty array if there is no data. And if your looping through you mind as well as process the information.





The third argument of GetDeviceData will be 0 if there is no current input in the buffer, just do that.

Tom

This topic is closed to new replies.

Advertisement