Solved

House tour goes FLOP

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

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

Title # Comments Views Activity
Help in WHSCRIPT 9 47
Opening Remote & Local Data Connection 2 51
VBA to copy paste columns form one file to other 20 86
Macro Excel - Multiple If conditions 2 65
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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.
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…

867 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

16 Experts available now in Live!

Get 1:1 Help Now