Skip to main content
gamedev.net
🔒 Locked

DirectInput Problems from hell

Started by cxi2 2 replies 200+ views
Original Post
cxi2
cxi2
ok I am going to hang myself soon if I dont get this simple procedure correct, PLEASE HELP All I want me program to do is PAUSE until a user presses the enter key. I am using DX7 and Direct INPUT . I set the cooperative level, and acquire the keyboard... then my code goes somewhat like this: unsigned long ITemData; ItemData = 64; DIDEVICEOBJECTDATA Sarray[64]; Keyboard->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), sArray, &ItemData); While (!(bob == 1)){ for(int i = 0; i > 64; i++){ if( Sarray.OFs = DIKS_RETURN){ bob = 1; } }// end for loop } I have tried sticking the Keyboard->GetDeviceData line in the while loop. what happens either way is that the program just hangs and accepts no input... I guess I dont have a clue how this works... can someoen show me some source for making the damn program pause until a key is pressed??????? thanks p.s. I tried getch()... doesnt work for some reason.... thanks all to Code, or Not To Code
to Code, or Not To Code
DekuTree64
DekuTree64
Here''s my input function (mostly just copied from the SDK samples...):
    void ProcessKeyboard(void)
{
#define KEYDOWN(name, key) (name[key] & 0x80)

char buf[256];
HRESULT hr = DIERR_INPUTLOST;

while(hr == DIERR_INPUTLOST)
{
hr = lpDIKB->GetDeviceState(sizeof(buf), (LPVOID)&buf);
if(hr == DIERR_INPUTLOST)
{
hr = lpDIKB->Acquire();
if(SUCCEEDED(hr))
break;
}
}
if(SUCCEEDED(hr))
{
//check keys, do stuff.
}
}[/source]

(hope I did that source thing right)
I''ve never really used it though, so it could probably use some improvement. Mainly making buf[] global, so other functions can check if keys are down, in which case the key checking part shouldn''t need to be there.
So basically, just make it look lke this:
[source]#define KEYDOWN(name, key) (name[key] & 0x80)
char buf[256];

void ProcessKeyboard(void)
{
HRESULT hr = DIERR_INPUTLOST;

while(hr == DIERR_INPUTLOST)
{
hr = lpDIKB->GetDeviceState(sizeof(buf), (LPVOID)&buf);
if(hr == DIERR_INPUTLOST)
{
hr = lpDIKB->Acquire();
if(SUCCEEDED(hr))
break;
}
}
}

So just make a while loop, call ProcessKeyboard, and ckeck if enter is down, if so, exit the loop^^




-Deku-chan

DK Art (my site, which has little programming-related stuff on it, but you should go anyway^_^)

"I'm dropping like flies!" - me, playing Super Smash Bros. (and losing)
"What fun!" - me, playing Super Smash Bros. (and beating the crap out of somebody)
furby100
furby100
You remembered to ->SetDataFormat(&c_dfDIKeyboard), I hope. Well, you want something like this:
    
unsigned char keystate[256];

Keyboard->GetDeviceState(256, keystate);
while(keystate[DIK_RETURN] & 0x80);


This is how I do it, I''ll give you a full example if you wish.

------------------------------
#pragma twice


sharewaregames.20m.com

cxi2
cxi2
sweet thanks guys... furby1000 wouldnt I want it to be like this:


unsigned char keystate[256];
Keyboard->GetDeviceState(256, keystate);
while(!(keystate[DIK_RETURN] & 0x80)){

// do stuff

}

? cuz I want the loop to continue forever unless the return key is hit...
maybe I dont understand the way the thing works: is the & 0x80 meaning that the key is up or down????

thanks guys


to Code, or Not To Code
to Code, or Not To Code

Topic Locked

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

Sign in to reply to this topic.