Solved

Using Arrow Keys in VB5

Posted on 1998-08-30
5
202 Views
Last Modified: 2010-04-30
I'd like to know how to detect the user pressing the arrow keys in vb5. A little example source would be plus :). And hey, it's worth 200 points.
0
Comment
Question by:loopdloop
  • 4
5 Comments
 
LVL 3

Accepted Solution

by:
a111a111a111 earned 200 total points
ID: 1431851
Option Explicit

Private Sub Form_Load()
    KeyPreview = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyF1: MsgBox "F1 is your friend."
        Case vbKeyF2: MsgBox "F2 could copy text."
        Case vbKeyF3: MsgBox "F3 could paste text."
        Case vbKeyF4: MsgBox "F4 could format text."
        Case vbKeyF4: MsgBox "F4 could format text."
       
    End Select
End Sub

I am working on arrow keys
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1431852
And here is the answer:

Option Explicit

Private Sub Form_Load()
    KeyPreview = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyLeft: MsgBox "Left"
        Case vbKeyRight: MsgBox "Right"
        Case vbKeyUp: MsgBox "up"
        Case vbKeyDown: MsgBox "Down"
    End Select
End Sub


shay@hili.com
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1431853
One more:

if you add a label  here is a code :

'*======start============

Option Explicit

Private Sub Form_Load()
    KeyPreview = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyLeft: Label1.Caption = "Left"
        Case vbKeyRight: Label1.Caption = "Right"
        Case vbKeyUp: Label1.Caption = "up"
        Case vbKeyDown: Label1.Caption = "Down"
    End Select
End Sub

'*========== end ==========

shay@hili.com
0
 

Author Comment

by:loopdloop
ID: 1431854
thanx a bunch! enjoy the points :)
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1431855
It is my pleasure to help and assist you.

Shay.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question