DirectInput problem

Started by
4 comments, last by _sid 19 years, 4 months ago
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
Advertisement
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."
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;
}
}

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.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

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
Yes thx to one little variable (is_down flag) i was able to finish my DI menu ... now it works just great.
Thx again all!

This topic is closed to new replies.

Advertisement