Sign in to follow this  

DirectInput problem

This topic is 4750 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi all Ive started to programm DI lately and everything was great till i tried to assign keys to the main menu of my prog. I mean it works with moving objects over the screen (up, down, etc...). It reads the keys (DIK_UP etc) and moves the object. But when i'm trying to assign keys to main menu of my prog the error occures... Sometimes only one action is commited (this is the way the prog should work) but sometimes two even three ... dunno what's wrong ... Maybe some of you had this prob before or knows whats wrong If no then i will post the code here and then wait for help :) Thx anyway _sid

Share this post


Link to post
Share on other sites
sounds possibly like you are using the same keys for more than one function..... to bypass this in my program, i use a 'map-trigger'. I create a variable called IsMapVisible (in your case IsMenuVisible), which is Boolean (true or false). Depending on the program branch currently executing, I check this variable to determine if the menu is visible or not. For example,

With DI_STATE
If .key(DIK_A)<> 0 and IsMapVisible=True then
' function for "A" key when the map is visible
end if
If .key(DIK_A)<>0 and IsMapVisivle=False then
' function for "A" key when the map(menu) is not visible
End if
End With

Alternatively, this could also be accomplished with nested if then statements:

With DI_STATE
If .key(DIK_A)<>0 then
If IsMapVisble then
' function for "A" key when the map is visible
End If
If Not IsMapVisble then
' function for "A" key when the map(menu) is not visible
End If
End With

-PicsesMike
"Boldly crashing systems where no man has had problems before."

Share this post


Link to post
Share on other sites
Damn, i wrote it wrong. What i ment was that action is being commited one two or three times. Maybe its my Keyboard state check proc:


bool CheckKeyboardState ()
{
HRESULT res = k_pDInputDeviceKeyboard->GetDeviceState(sizeof(unsigned char)*256, (LPVOID) &iKeyBuffer);

if( FAILED(res) && (res==DIERR_INPUTLOST) )
{
if( FAILED(k_pDInputDeviceKeyboard->Acquire()) )
return FAIL;
}
else
{
return FAIL;
}

return SUCC;
}

Maybe i should reset the iKeyBuffer everytime after checkin Keys state ...

My checking proc looks like this:

if(IsButtonDown(DIK_DOWN))
{
FillPartSurface(&Tlo, posX, posY, 356, 60, ButtonIMG);

if(posY<243)
{
posY+=113;
}
else
{
posY=17;
}
}

Share this post


Link to post
Share on other sites
Your code will check if the key is currently down.

Now if the user keeps pressing the key for a longer time this check will call the function every time. You need to add a has-been-released-flag for that case.

The released-flag starts off as true. The check will not only check if the key is pressed but also if it has the released flag set.
Once the key has been pressed and you're inside the check, set the released flag to false. Only set the released flag to true, if the key down flag is not set.


Imagine the keyboard state as a huge gamepad. You will not get the flag for a pressed key only once, it shows the actual key states at the current time.

Share this post


Link to post
Share on other sites
oww yes. Now i see whats wrong.
Just need to proceed when the button is being released.

Thx all ! Will write if everything is ok with my menu :D

Share this post


Link to post
Share on other sites

This topic is 4750 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this