Solved

converting e.KeyCode to the keyboard value in a message

Posted on 2009-03-29
4
1,195 Views
Last Modified: 2013-11-26
How do I convert e.KeyCode to the actual keyboard key name like "F1" where the line of code would look like:

MsgBox(ConvertThis(e.KeyCode) & " is an invalid key. Please choose F2 through F9 only.", CType((MsgBoxStyle.Information + MsgBoxStyle.OkOnly), MsgBoxStyle), "Lenny's Message")

Where ConvertThis is a function that will convert e.KeyCode to the function key or keyboard character that the user depressed.

The messagebox would have this message, if the F1 key was depressed by the user:

F1 is an invalid key. Please choose F2 through F9 only.

Thanks!

Lenny
0
Comment
Question by:LennyGray
  • 2
  • 2
4 Comments
 
LVL 7

Expert Comment

by:cmrobertson
ID: 24013028
if e.KeyCode = keys.F10 etc.
0
 
LVL 10

Author Comment

by:LennyGray
ID: 24013053

I already knew that because I have case statements for all of the keys that I want to react to from F2 to F9.

            Case Keys.F1, Keys.F10, Keys.F11, Keys.F12
                MsgBox(ChrW(e.KeyCode) & " is an invalid key. Please choose F2 through F9 only.", CType((MsgBoxStyle.Information + MsgBoxStyle.OkOnly), MsgBoxStyle), "Lenny's Message")
                e.Handled = True
        End Select

ChrW gives me a "p" when I hit F1 not "F1"

Thanks, but I wanted something more automatic. Case Else is no good because it picks up all keys depressed.

Maybe this will give you an idea of what I am trying to do.

Lenny
0
 
LVL 7

Accepted Solution

by:
cmrobertson earned 500 total points
ID: 24013121
not sure if you want to get rid of the case statement or just supply the key if it is the latter then this will work
e.keydata.tostring
0
 
LVL 10

Author Closing Comment

by:LennyGray
ID: 31564040
Perfect !!!

Thanks a lot. I have 38 years of database programming experience but I am just learning dot net. Be prepared to earn a lot of points from me!
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 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