Solved

House tour goes FLOP

Posted on 1998-12-19
4
147 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 20 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
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 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…

705 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