DX and DI 
Author Message
 DX and DI

im having a problem with DI,,
im using this little code, and it just dosent work in the way that it is
supposed to:

'*** from my module
Public DInput As DirectInput
Public DKeyboard As DirectInputDevice
Public KeyState As DIKEYBOARDSTATE
Public iMenu As Integer

sub main()
Dim lTimeTemp As Long
DKeyboard.Unacquire
Call CreateGraphicsFromFile("bg", BackgroundSurf, BackgroundSurfDesc, 640,
480)
Call CreateGraphicsFromFile("menu", MenuSurf, MenuSurfDesc, 250, 200)
Call CreateGraphicsFromFile("menuclicked", MenuClickedSurf,
MenuClickedSurfDesc, 250, 200)
iPosition = 660
iMenu = 1
Debug.Print iMenu
Do
lTimeTemp = timeGetTime
DKeyboard.Acquire
Call BltColorFill(rPrimSurf, RGB(0, 0, 0))
DrawBackground
FixMenus
DrawScrollingText
PrimSurf.Flip Nothing, DDFLIP_WAIT
DKeyboard.GetDeviceStateKeyboard KeyState
If KeyState.Key(DIK_ESCAPE) <> 0 Then
DDestroy
End If
'******* here is the problem
If KeyState.Key(DIK_DOWN) <> 0 Then
If iMenu <> 4 Then
iMenu = iMenu + 1
Debug.Print iMenu
End If
End If
If KeyState.Key(DIK_UP) <> 0 Then
If iMenu <> 1 Then
iMenu = iMenu - 1
End If
End If
'******** ends here
Do Until timeGetTime >= lTimeTemp + 25.6666666666667
'loops until frame rate met
Loop
Loop
end sub

when i run the program and press an arrow key it like press the key 50000
million times,, so if imenu is 1 and i press arrow down it goes past 2 3 and
goes to 4, on the output from the debug it says,,,
1
1
1
1
1
1
1
1
2
3
4
4
4
4
4
4

when i just press the key once..?
i have tried to add,
DKeyBoard.Unaquire ' after the timeframe loop, but that dosent work either
since my program dosent recive any input if i do it like that, and i tried
this aswell:
KeyState.Key(DIK_DOWN) = 0
and
KeyState.Key(DIK_UP) = 0
like this:
If KeyState.Key(DIK_UP) <> 0 Then
If iMenu <> 1 Then
iMenu = iMenu - 1
End If
KeyState.Key(DIK_UP) = 0
End If

dosent work either,,  any ideas??

regards
patrick



Tue, 04 Jan 2005 18:52:09 GMT  
 DX and DI
DI was intended first for game input, that is it returns the *current*
status. Though you could implement this using DI (using buffered mode
instead of the immediate mode, see "Buffered Keyboard Data" in the
documentation), for a menu I would just use the usual even driven cooked
system...

Patrice



Quote:
> im having a problem with DI,,
> im using this little code, and it just dosent work in the way that it is
> supposed to:

> '*** from my module
> Public DInput As DirectInput
> Public DKeyboard As DirectInputDevice
> Public KeyState As DIKEYBOARDSTATE
> Public iMenu As Integer

> sub main()
> Dim lTimeTemp As Long
> DKeyboard.Unacquire
> Call CreateGraphicsFromFile("bg", BackgroundSurf, BackgroundSurfDesc, 640,
> 480)
> Call CreateGraphicsFromFile("menu", MenuSurf, MenuSurfDesc, 250, 200)
> Call CreateGraphicsFromFile("menuclicked", MenuClickedSurf,
> MenuClickedSurfDesc, 250, 200)
> iPosition = 660
> iMenu = 1
> Debug.Print iMenu
> Do
> lTimeTemp = timeGetTime
> DKeyboard.Acquire
> Call BltColorFill(rPrimSurf, RGB(0, 0, 0))
> DrawBackground
> FixMenus
> DrawScrollingText
> PrimSurf.Flip Nothing, DDFLIP_WAIT
> DKeyboard.GetDeviceStateKeyboard KeyState
> If KeyState.Key(DIK_ESCAPE) <> 0 Then
> DDestroy
> End If
> '******* here is the problem
> If KeyState.Key(DIK_DOWN) <> 0 Then
> If iMenu <> 4 Then
> iMenu = iMenu + 1
> Debug.Print iMenu
> End If
> End If
> If KeyState.Key(DIK_UP) <> 0 Then
> If iMenu <> 1 Then
> iMenu = iMenu - 1
> End If
> End If
> '******** ends here
> Do Until timeGetTime >= lTimeTemp + 25.6666666666667
> 'loops until frame rate met
> Loop
> Loop
> end sub

> when i run the program and press an arrow key it like press the key 50000
> million times,, so if imenu is 1 and i press arrow down it goes past 2 3
and
> goes to 4, on the output from the debug it says,,,
> 1
> 1
> 1
> 1
> 1
> 1
> 1
> 1
> 2
> 3
> 4
> 4
> 4
> 4
> 4
> 4

> when i just press the key once..?
> i have tried to add,
> DKeyBoard.Unaquire ' after the timeframe loop, but that dosent work either
> since my program dosent recive any input if i do it like that, and i tried
> this aswell:
> KeyState.Key(DIK_DOWN) = 0
> and
> KeyState.Key(DIK_UP) = 0
> like this:
> If KeyState.Key(DIK_UP) <> 0 Then
> If iMenu <> 1 Then
> iMenu = iMenu - 1
> End If
> KeyState.Key(DIK_UP) = 0
> End If

> dosent work either,,  any ideas??

> regards
> patrick



Tue, 04 Jan 2005 19:23:25 GMT  
 DX and DI
i solved the problem,, not the best way to do it, but it works...

if anyone got a better way then this, please let me know.

 '*** from my module
 Public DInput As DirectInput
 Public DKeyboard As DirectInputDevice
 Public KeyState As DIKEYBOARDSTATE
 Public LastKeyState As DIKEYBOARDSTATE
 Public iMenu As Integer

sub main()
Dim lTimeTemp As Long

Call CreateGraphicsFromFile("bg", BackgroundSurf, BackgroundSurfDesc, 640,
480)
Call CreateGraphicsFromFile("menu", MenuSurf, MenuSurfDesc, 250, 200)
Call CreateGraphicsFromFile("menuclicked", MenuClickedSurf,
MenuClickedSurfDesc, 250, 200)

iPosition = iPositionStartValue
iMenu = 1

Do
lTimeTemp = timeGetTime

DKeyboard.Acquire
DKeyboard.GetDeviceStateKeyboard KeyState

If KeyState.Key(DIK_ESCAPE) <> 0 Then
DDestroy
End If

'***** problem area, fixed with the lastkeystate
' if the arrow down key is pressed and the last pressed key has been set to
0
If KeyState.Key(DIK_DOWN) <> 0 And LastKeyState.Key(DIK_DOWN) = 0 Then
If iMenu <> 4 Then
iMenu = iMenu + 1
End If
End If

' if the arrow up key is pressed and the last pressed key has been set to 0
If KeyState.Key(DIK_UP) <> 0 And LastKeyState.Key(DIK_UP) = 0 Then
If iMenu <> 1 Then
iMenu = iMenu - 1
End If
End If
'***********end problem ******************'

' ************fix the problem code****************
' set the pressed key to lastpressed key and wait for the key to be
released, when the key is released lastpressed key will return to 0
For y = 0 To 255
If KeyState.Key(y) <> 0 Then
LastKeyState.Key(y) = KeyState.Key(y)
End If
If LastKeyState.Key(y) <> KeyState.Key(y) Then
LastKeyState.Key(y) = 0
End If
Next y
'*********************************************''

Call BltColorFill(rPrimSurf, RGB(0, 0, 0))
DrawBackground
FixMenus
DrawScrollingText
PrimSurf.Flip Nothing, DDFLIP_WAIT

Do Until timeGetTime >= lTimeTemp + 25.6666666666667
'loops until frame rate met
Loop

Loop
end sub



Quote:
> DI was intended first for game input, that is it returns the *current*
> status. Though you could implement this using DI (using buffered mode
> instead of the immediate mode, see "Buffered Keyboard Data" in the
> documentation), for a menu I would just use the usual even driven cooked
> system...

> Patrice



> > im having a problem with DI,,
> > im using this little code, and it just dosent work in the way that it is
> > supposed to:

> > '*** from my module
> > Public DInput As DirectInput
> > Public DKeyboard As DirectInputDevice
> > Public KeyState As DIKEYBOARDSTATE
> > Public iMenu As Integer

> > sub main()
> > Dim lTimeTemp As Long
> > DKeyboard.Unacquire
> > Call CreateGraphicsFromFile("bg", BackgroundSurf, BackgroundSurfDesc,
640,
> > 480)
> > Call CreateGraphicsFromFile("menu", MenuSurf, MenuSurfDesc, 250, 200)
> > Call CreateGraphicsFromFile("menuclicked", MenuClickedSurf,
> > MenuClickedSurfDesc, 250, 200)
> > iPosition = 660
> > iMenu = 1
> > Debug.Print iMenu
> > Do
> > lTimeTemp = timeGetTime
> > DKeyboard.Acquire
> > Call BltColorFill(rPrimSurf, RGB(0, 0, 0))
> > DrawBackground
> > FixMenus
> > DrawScrollingText
> > PrimSurf.Flip Nothing, DDFLIP_WAIT
> > DKeyboard.GetDeviceStateKeyboard KeyState
> > If KeyState.Key(DIK_ESCAPE) <> 0 Then
> > DDestroy
> > End If
> > '******* here is the problem
> > If KeyState.Key(DIK_DOWN) <> 0 Then
> > If iMenu <> 4 Then
> > iMenu = iMenu + 1
> > Debug.Print iMenu
> > End If
> > End If
> > If KeyState.Key(DIK_UP) <> 0 Then
> > If iMenu <> 1 Then
> > iMenu = iMenu - 1
> > End If
> > End If
> > '******** ends here
> > Do Until timeGetTime >= lTimeTemp + 25.6666666666667
> > 'loops until frame rate met
> > Loop
> > Loop
> > end sub

> > when i run the program and press an arrow key it like press the key
50000
> > million times,, so if imenu is 1 and i press arrow down it goes past 2 3
> and
> > goes to 4, on the output from the debug it says,,,
> > 1
> > 1
> > 1
> > 1
> > 1
> > 1
> > 1
> > 1
> > 2
> > 3
> > 4
> > 4
> > 4
> > 4
> > 4
> > 4

> > when i just press the key once..?
> > i have tried to add,
> > DKeyBoard.Unaquire ' after the timeframe loop, but that dosent work
either
> > since my program dosent recive any input if i do it like that, and i
tried
> > this aswell:
> > KeyState.Key(DIK_DOWN) = 0
> > and
> > KeyState.Key(DIK_UP) = 0
> > like this:
> > If KeyState.Key(DIK_UP) <> 0 Then
> > If iMenu <> 1 Then
> > iMenu = iMenu - 1
> > End If
> > KeyState.Key(DIK_UP) = 0
> > End If

> > dosent work either,,  any ideas??

> > regards
> > patrick



Tue, 04 Jan 2005 23:14:51 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Finestra di errore di sistema in fase di copia files

2. outlook Bar control di Daniele di Alessandro

3. enumerazione di risorse di rete!

4. Prova di trasmissione, non vale la pena di leggere.

5. Find di record con ADO su un database Betrieve !!!!! Errore di Run-Time 2147217879(80040e29)

6. :DX SDK

7. Is there a work-around for installing MSDE on a i486 DX 100mhz

8. DirectDraw (Dx 9.0 Managed) - How to scale and write text

9. DX SDK 9.1

10. About DX 8 and 9

11. Starting DX with VB

12. Dx libraries don't appear in list.

 

 
Powered by phpBB® Forum Software