Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

converting e.KeyCode to the keyboard value in a message

Posted on 2009-03-29
4
Medium Priority
?
1,200 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

721 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