Keys, member names, and button labels

clemon79

Newcomer
Joined
Jun 12, 2007
Messages
2
Location
Seattle, WA
Hi! I'm new here, and I've picked up a VB project I've been working on for a long time after letting it rot for a year. I'm gonna tell you up front now: I'm pretty much a novice with this, and I'm feeling my way through as I go. So I throw myself at your mercy. :)

Anyhow, here's the deal: the app I'm working on is a game-show-style lockout system, and I have an Options screen that the users can access to decide which players use which buttons to buzz in. Basically, you hit a button, it pops up a form asking you to hit the key you want that player to use, and the form closes and sends back the KeyValue of the key.

Right now, I have the form displaying that numeric value on the button so you know what keys you have assigned to who. However, what I WANT to do is display the Member Name, as in the list found at:

http://msdn2.microsoft.com/en-us/library/system.windows.forms.keys(VS.80).aspx

So for example, the "1" key not on the numeric pad has a KeyValue of 49. However, the Member Name of that key is "D1". I want to be able to display "D1" on that button. But I can't figure out how to extract that string, given the corresponding KeyValue.

Does anyone know how I might go about that? I KNOW it's something easy, it's gotta be, I just don't know the syntax of how to do it.

(It looks like it involves KeysConverter somehow, but I don't have any idea how to use that.)

Thanks!

-- Chris
 
Last edited:
If you just want the string of the KeyCode the following is a very basic example. If I've mis-understood your question let me know...
C#:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
MessageBox.Show(e.KeyCode.ToString());
}
 
If you just want the string of the KeyCode the following is a very basic example. If I've mis-understood your question let me know...
C#:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
MessageBox.Show(e.KeyCode.ToString());
}
Well, honestly I don't know.

So here's what I have in the code for the dialog that gets the key:
C#:
    Private Sub GetKeyDialog_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        '_KeyInteger = TypeDescriptor.GetConverter(e.KeyData).ConvertTo(Of Integer)(e.KeyData)
        _KeyInteger = e.KeyValue
        _KeyString = TypeDescriptor.GetConverter(e.KeyCode).ConvertToString(e.KeyCode)
        Me.Close()
    End Sub
And that seems to work, but: According to this article:

http://msdn2.microsoft.com/en-us/library/system.windows.forms.keys(VS.71).aspx

(and someone PLEASE explain to me why the .NET 1.1 article has that list of numbers and the .NET 2.0 article doesn't?)

...the Left Shift and Right Shift keys have their own values, but the above method only seems to get "SHIFT" for either shift key, or either Control key, and I don't know if there is an easy way to get those values from a KeyDown instead of the base SHIFT value I'm getting.

I'm probably making no sense, and right now I'm thinking that I really should just stick to Hello World and quit deceiving myself that I could actually figure this out, but there it is.
 
Back
Top