?
Solved

House tour goes FLOP

Posted on 1998-12-19
4
Medium Priority
?
149 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month12 days, 5 hours left to enroll

752 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