?
Solved

House tour goes FLOP

Posted on 1998-12-19
4
Medium Priority
?
152 Views
Last Modified: 2010-05-03
I have an application in which you are in a virtual tour of my house.  I have 8 arrow buttons each pointing in a different direction.  Along with being able to click these buttons to move, I also want them to be able to press a number on the numeric keypad.  My form's KeyPreview property is set to True and I am using the KeyPress event to monitor each press of the key.  This is where the problem comes up.  Every time a key is pressed, my program goes through a Select Case on KeyAscii.  On each case it has the vbKeyNumpad1,2,3,4,etc. variables for each of the directions.  I want this to work whether the NumLock button is lit or not.  Is this possible?
0
Comment
Question by:TomKid2004
4 Comments
 
LVL 1

Expert Comment

by:muffinthedog
ID: 1451511
TomKid2004,
    Why not get the state of the NumLock key with something like...

GetKeyState(vbKeyNumlock) and switch accordingly
will return 0 if NumLocks off, 1 if on in keypress event

Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer


0
 
LVL 1

Expert Comment

by:RichardE
ID: 1451512
Look at the KeyDown event instead of KeyPress. Here you can Select/Case on KeyCode and act accordingly. The KeyAscii from the KeyPress does not equate to KeyCode - play with it.
0
 

Author Comment

by:TomKid2004
ID: 1451513
I was hoping for some source code or something.  I tried it though and it still only works when the NumLock is off.

Thanks anyway,
              Tom
0
 
LVL 3

Accepted Solution

by:
jbil earned 60 total points
ID: 1451514
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode
    Case 103, 36
     Label1.Caption = "NW" 'do your things here
    Case 104, 38
     Label1.Caption = "N"
    Case 105, 33
     Label1.Caption = "NE"
    Case 99, 34
    Label1.Caption = "SE"
    Case 102, 39
     Label1.Caption = "E"
    Case 98, 40
     Label1.Caption = "S"
    Case 97, 35
     Label1.Caption = "SW"
    Case 100, 37
     Label1.Caption = "W"
    Case Else
     Label1.Caption = Label1.Caption
    End Select
   
End Sub
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

830 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