Solved

House tour goes FLOP

Posted on 1998-12-19
4
142 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 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

15 Experts available now in Live!

Get 1:1 Help Now