Advertisement

I'm really in need of help =(

Started by August 07, 2002 04:54 AM
4 comments, last by the_recon 22 years, 6 months ago
I really can't see what I'm doing wrong so I've come here for your guidance I am trying to do DirectInput in Dx8 But I can't get it to work. I've made a DInput singleton class with a function called IsKeyDown(int dik); and it goes somewhat like this: bool IsKeyDown(int dik) { return(m_instance->diKeys[dik] & 0x80); } and is supposed to be used like this: If(DInput.IsKeyDown(DIK_UP)) Cam.Move(0.001f); The problem is that the camera moves, spins, etc. Eventhough I haven't pressed the up-arrow key. Has anyone else had this problem or am I the only one? =/ Please help. [edited by - the_recon on August 7, 2002 6:21:28 AM]
Js
Are you clearing and/or filling the key state array properly?


Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
Advertisement
I''m usin the following function to fill the array:

GetKeyboardState(void)
{
if(m_instance)
{
m_instance->lpdiKeyboard->GetDeviceState(sizeof(UCHAR[256]),(LPVOID)&m_instance->diKeys);
return(1);
}
return(-1);
}

I think this is the way to do it. Am I wrong?
Js
What does GetDeviceState return? Does it succeed? Also, if your instance isn''t present the array will be filled with crap.


Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
try this:

int KeyDown(char* buffer,int state)
{
if(buffer[state]&0x80){
return 1;
}
return 0;
}

I think this should work.

-----------------------------------------or:

#define KeyDown(buffer,data) buffer[data]&0x80 ? true:false

then do this:

if(KeyDown(inputbuffer,DIK_X))
{
//your code
}

This should work for sure.

.lick

[edit]made it more readable



[edited by - pipo declown on August 7, 2002 7:21:01 AM]
Well, I just rechecked my code and made my program do some error checking when it was checking th ekeyboard's state. And guess what? The Device hadn't been acquired eventhough It tries to Acquire the device in the init-phase. Strange but now it works.

Thanks for all your help guys! You've all been very helpful!
[Edited due to wrong avatar]
[Edited (again) due to wrong avatar (again)]



[edited by - the_recon on August 7, 2002 8:01:59 AM]
Js

This topic is closed to new replies.

Advertisement