Link to home
Start Free TrialLog in
Avatar of LennyGray
LennyGrayFlag for United States of America

asked on

converting e.KeyCode to the keyboard value in a message

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
Avatar of cmrobertson
cmrobertson
Flag of United States of America image

if e.KeyCode = keys.F10 etc.
Avatar of LennyGray

ASKER


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
ASKER CERTIFIED SOLUTION
Avatar of cmrobertson
cmrobertson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!