key states

in this code i'm trying to check the keystate of the "up" arrow key, and then if it's true, move the picture box. it runs, but nothing happens. i also get the error "cannot convert integer to boolean" in the ***** line. any ideas??

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As _Integer

' The state of the Up key
Dim vbkeyup As Integer

Function UpKey() As Boolean

**** UpKey = (GetAsyncKeyState(vbkeyup) And &H26) ****

If UpKey() = True Then
PictureBox2.Top -= 50
End If
End Function

Comments

  • : in this code i'm trying to check the keystate of the "up" arrow key, and then if it's true, move the picture box. it runs, but nothing happens. i also get the error "cannot convert integer to boolean" in the ***** line. any ideas??
    :
    : Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As _Integer
    :
    : ' The state of the Up key
    : Dim vbkeyup As Integer
    :
    : Function UpKey() As Boolean
    :
    : **** UpKey = (GetAsyncKeyState(vbkeyup) And &H26) ****
    :
    : If UpKey() = True Then
    : PictureBox2.Top -= 50
    : End If
    : End Function
    :
    try this line instead ...

    If cbool(upKey) Then

    If Option Strict is on then you have to explicitly conevrt integers to boolean if you are testing for true or false


  • : in this code i'm trying to check the keystate of the "up" arrow key, and then if it's true, move the picture box. it runs, but nothing happens. i also get the error "cannot convert integer to boolean" in the ***** line. any ideas??
    :
    : Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As _Integer
    :
    : ' The state of the Up key
    : Dim vbkeyup As Integer
    :
    : Function UpKey() As Boolean
    :
    : **** UpKey = (GetAsyncKeyState(vbkeyup) And &H26) ****
    :
    : If UpKey() = True Then
    : PictureBox2.Top -= 50
    : End If
    : End Function
    :

    Why not like this:

    Protected Overrides Sub OnKeyDOwn(...)
    Select Case e.KeyValue)
    Case Keys.Up : PictureBox1.Top -= 10
    Case Keys.Down : PictureBox1.Top += 10
    Case Keys.Left : PictureBox1.Left -= 10
    Case Keys.Right : PictureBox1.Left += 10
    End Select
    End Sub
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories