
-----------------------------------
Darkmantis
Thu May 11, 2006 6:38 pm

How do I get VB to recognise two buttons are being pressed?
-----------------------------------
in my side scroller rpg I can't figure out how to get my guy to jump diagonally by pressing 2 buttons it either doesnt work or badly bugs out on me. What do I do?

-----------------------------------
Brightguy
Wed May 24, 2006 3:05 pm

Re: How do I get VB to recognise two buttons are being press
-----------------------------------
You're looking for the If GetKeyState(vbKeyLeft) And &H8000 Then
    LeftPos = LeftPos + 1
End If
That just checks if the high bit is set (in VB an expression is only false if it evaluates to zero).

-----------------------------------
Darkmantis
Thu May 25, 2006 6:24 am


-----------------------------------
can you plz explain this code more I dont understand how it works.

-----------------------------------
Brightguy
Sat May 27, 2006 10:14 pm

Re: How do I get VB to recognise two buttons are being press
-----------------------------------
First of all, when you use a WinAPI function you must declare it in the beginning of the module, for example:

Private Declare Function GetKeyState Lib "user32" Alias "GetKeyState" (ByVal nVirtKey As Long) As Integer
This particular function takes a single parameter, corresponding to the key you want to determine the state of.  (You can use the VB Key Code Constants for this, e.g. vbKeyA, vbKeyB, etc.)

The function returns an Integer which will tell you if the key is pressed or not - if the high bit is set then the key is pressed.  (You need to know a little about binary numbers for this.)  An Integer is two bytes (thus 16 bits), and the high bit is the left-most of them.

A [url=http://en.wikipedia.org/wiki/Bitwise_operation#AND]bitwise AND compares the same-positioned bits of two numbers.  To determine if the high bit is set, use a bit mask: compare the Integer with the binary number that has only the high bit set (10000000 00000000, represented in hex by &H8000).  So in the example code I posted, LeftPos is only incremented when the left key is pressed.

-----------------------------------
Darkmantis
Sun May 28, 2006 10:08 am


-----------------------------------
thx, ill try to use this code, ill post again if I get it to work or not.
