Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

converting e.KeyCode to the keyboard value in a message

Posted on 2009-03-29
4
Medium Priority
?
1,206 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 2000 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
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…

963 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