Solved

converting e.KeyCode to the keyboard value in a message

Posted on 2009-03-29
4
1,191 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

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

18 Experts available now in Live!

Get 1:1 Help Now