Qbasicnews.com

Full Version: Detecting mutiple key inputs in Visual Basic 5
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, i'm making a simple game in Visual Basic 5

The player needs the abilty to press 1 or more keys on the keyboard at the same time.

ex.

Pressing "w" makes a image go up
Pressing "d" makes a image go right
Pressing "s" makes a second image appear

Pressing all of them at the same time makes the image move digonally to the right and the second image to appear.

I've searched and searched for it, and still nothing.

Thank you in advance.
Look into DirectInput. There are gobs of tuts everywhere.
Thanks for your response, but i'd prefer if I could use something else then DirectX. The game i'm making will eventally run on a school computer, and no it's not a homework assignment (I'm making it for fun at home ^-^), so I want to make sure it just runs without being dependent on something else. Is there like a block of code that will do the trick.
Well, in that case, I would try GetAsyncKeyState.

Code:
Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Integer) As Integer

...

If GetAsyncKeyState(VK_SPACE) Then
' do something
End If

You'll of course need the VK_* constants; they're here.
I'll try it out, thanks ^-^.

Also i'll post my game when it's done, it is a little space shooter where you just fly around and survive as long as you can.
I put in:

Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Integer) As Integer

(The reason why it's Private is because without it, the program gives me a error) On top of all the code and:

Code:
If GetAsyncKeyState(VK_SPACE) Then ShipYAxisMove = ShipYAxisMove + 1.5

In a timer code and it doesn't do anything when I press space.

Also i'm placing all this in the form code window, just in case if you were wondering.
The VK_* numbers on that MSDN page are in hex, so you have to do something like
Code:
Const VK_SPACE As Integer = &H20
Quote:Thanks for your response, but i'd prefer if I could use something else then DirectX. The game i'm making will eventally run on a school computer, and no it's not a homework assignment (I'm making it for fun at home ^-^), so I want to make sure it just runs without being dependent on something else. Is there like a block of code that will do the trick.

Eh? Wouldn't Directx be as portable on any school system as anything?
To barok:

The reason why I don't want to use DirectX is because the school is a tad... "protective" about there computers. I'm not sure how much ability they have to track what I run on the computer, but if they can detect if DirectX was use for something they might try to get me hanged for it (Like one time I was trying to adjust the comp's monitor settings to make it better, the teacher instantly comes over and threatens if I do that ever again I would be kicked of the computer for the rest of the year, thust failing the course). Also I have no idea what version they have. Did I mention there computer Nazi... oh I mean "protective". If you were wondering it's not a collage computer just a public school one.

To DrV:

That did the trick. At first I was confused but then I relized the "&H" needed to be put in front of the Hex value. So all I needed to do is insted of...

Code:
If GetAsyncKeyState(57) Then ShipYAxisMove = ShipYAxisMove + 1.5 'Key Handeler for Up

It would be...

Code:
If GetAsyncKeyState(&H57) Then ShipYAxisMove = ShipYAxisMove + 1.5 'Key Handeler for Up

Thanks =D