reacting to keyup?! - Programmers Heaven

Howdy, Stranger!

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

Categories

reacting to keyup?!

Joe2003Joe2003 Posts: 92Member
Hey

I have a pannel, all I want to do is if the user presses the up key I want a textbox to appear that says "UP", if they press down a textbox to appear that says "DOWN" and so on for left and right.

is this possible, I have been trying to use the keyup event handler but I cant get it to work.

cheers

Joel


Comments

  • lionblionb Posts: 1,688Member ✭✭
    : Hey
    :
    : I have a pannel, all I want to do is if the user presses the up key I want a textbox to appear that says "UP", if they press down a textbox to appear that says "DOWN" and so on for left and right.
    :
    : is this possible, I have been trying to use the keyup event handler but I cant get it to work.
    :
    : cheers
    :
    : Joel
    :
    [code]
    Private Sub Form_Load()
    Text1.Visible = False
    End Sub

    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then 'left button pressed
    Text1.Text = "DOWN"
    Text1.Visible = True
    End If
    End Sub

    Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then 'left button pressed
    Text1.Text = "UP"
    Text1.Visible = True
    End If

    End Sub
    [/code]


  • Mike_AB1Mike_AB1 Posts: 49Member
    : Hey
    :
    : I have a pannel, all I want to do is if the user presses the up key I want a textbox to appear that says "UP", if they press down a textbox to appear that says "DOWN" and so on for left and right.
    :
    : is this possible, I have been trying to use the keyup event handler but I cant get it to work.
    :
    : cheers
    :
    : Joel
    :
    :
    :

    Try this:

    [Code]
    Private Sub Form_Load()
    '''This way no matter which control has focus - all the key events will be processed by the form
    Form1.KeyPreview = True '''you can set this in the form properties
    End Sub
    Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    With Text1
    Select Case KeyCode
    Case vbKeyUp
    .Text = "Up"
    Case vbKeyDown
    .Text = "Down"
    Case vbKeyLeft
    .Text = "Left"
    Case vbKeyRight
    .Text = "Right"
    Case Else
    .Text = ""
    End Select
    End With
    End Sub
    [/Code]

    Mike
Sign In or Register to comment.