Solved

Using Arrow Keys in VB5

Posted on 1998-08-30
5
194 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now