[Help]Quick Simple Fast Question[Solved]

Posts 1–13 of 13 · Page 1 of 1
[Help]Quick Simple Fast Question[Solved]
How do i get the pressed key?

I did this:
Code:
    Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Form1.KeyPress
        Dim PressedKey As String = Asc(e.KeyChar)
        Label1.Text = PressedKey
    End Sub
But i want to get F5 and that keys..
Try this:

Code:
Label1.Text = e.KeyChar.ToString
Quote Originally Posted by Jason View Post
Try this:

Code:
Label1.Text = e.KeyChar.ToString
Works like my code...


But i want to get the FX Keys .. Like F5 F6 etc..

I need to GetAsyncKeyState?
Handle the keydown then:

Code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    Label1.Text = CType(e.KeyCode, Keys).ToString
End Sub
Quote Originally Posted by Jason View Post
Handle the keydown then:

Code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    Label1.Text = CType(e.KeyCode, Keys).ToString
End Sub
WOW , Thanks man.

You pro!

/SOLVED
Quote Originally Posted by Jason View Post
Handle the keydown then:

Code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    Label1.Text = CType(e.KeyCode, Keys).ToString
End Sub
if I can make you a question....Why call the CType function?
Quote Originally Posted by user590177 View Post
if I can make you a question....Why call the CType function?
"Keys" is an enum. So basically what I did was convert the integer represented in "e.KeyCode" to it's counterpart in the enum (the one with the same value as the integer) then called ".ToString" to convert this into a string. For example, say I have an enum like this:

Code:
Enum Test
  Test1 = 1
  Test2 = 2
  Test3 = 69
End Enum


And I have the integer 69, so I want to get the string "Test3" from the enum.

Code:
CType(69, Test).ToString


I convert 69 to it's counterpart in the Enum (i.e the Test3 block) then call ".ToString" to get the name of the block ("Test3")
Quote Originally Posted by Jason View Post


"Keys" is an enum. So basically what I did was convert the integer represented in "e.KeyCode" to it's counterpart in the enum (the one with the same value as the integer) then called ".ToString" to convert this into a string. For example, say I have an enum like this:

Code:
Enum Test
  Test1 = 1
  Test2 = 2
  Test3 = 69
End Enum


And I have the integer 69, so I want to get the string "Test3" from the enum.

Code:
CType(69, Test).ToString


I convert 69 to it's counterpart in the Enum (i.e the Test3 block) then call ".ToString" to get the name of the block ("Test3")
oh yea, so basically you simply converted the Integer of the key in the enum to a string value...
I did understand thanks....oh and an other function, can we convert it using DirectCast for ie?
Quote Originally Posted by user590177 View Post
oh yea, so basically you simply converted the Integer of the key in the enum to a string value...
I did understand thanks....oh and an other function, can we convert it using DirectCast for ie?
Yeah DirectCast is similar to CType however it has become obsolete and CType is favored over it.

EDIT: 2700th post. Yay?
Quote Originally Posted by Jason View Post


Yeah DirectCast is similar to CType however it has become obsolete and CType is favored over it.

EDIT: 2700th post. Yay?
thx again for answering my questions, ure great!

P.S.
GJ on 2,700!
Plus, DirectCast has been obsolete for awhile, it's only a matter of time before it is completely removed form the framework, meaning somewhere download the line, apps using directcast will fail.

Stick to ctype.
Quote Originally Posted by NextGen1 View Post
Plus, DirectCast has been obsolete for awhile, it's only a matter of time before it is completely removed form the framework, meaning somewhere download the line, apps using directcast will fail.

Stick to ctype.
I know I'm not supposed to post now, but who was having a little hissy fit about DirectCast being obsolete 2 days ago Rich? So much for kicking it oldschool.
I do hate the fact that it is obsolete, so much of my past applications use direccast over Ctype, so eventually there may be a lot of failing apps.

But, Still sharing the truth, it is Obsolete
Posts 1–13 of 13 · Page 1 of 1
This thread is closed for replies.

Tags for this Thread

None

Talk with us