1 Attachment(s)
hex + decimal keycodes utility
heres a hex + decimal keycodes utility (see attachment)
vb.net Code:
Public Class Form1
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
Label3.Text = "key - " & e.KeyCode.ToString
txtDecimal.Text = e.KeyCode
txtHexadecimal.Text = "&H" & Hex(Long.Parse(e.KeyCode))
End Sub
End Class
Re: hex + decimal keycodes utility
e.KeyCode is already a number. Implicitly converting it to a String in order to parse it in order to convert it to a String is a bit roundabout, not to mention that it won't compile with Option Strict On.
vb.net Code:
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
Label3.Text = "key - " & e.KeyCode.ToString()
txtDecimal.Text = CStr(e.KeyCode)
txtHexadecimal.Text = "&H" & e.KeyCode.ToString("X")
End Sub
Re: hex + decimal keycodes utility
returns keyname - i.e. ctrl, alt tab etc.
i didn't really need to put the there though
Re: hex + decimal keycodes utility
heres the improved version
vb Code:
Public Class Form1
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
Label3.Text = "key - " & e.KeyCode.ToString
txtDecimal.Text = e.KeyCode
txtHexadecimal.Text = "&H" & Hex(e.KeyCode)
End Sub
End Class
Re: hex + decimal keycodes utility
That still won't compile with Option Strict On, which everyone should have all the time unless they specifically need it Off. That's why I used this:
vb.net Code:
txtDecimal.Text = CStr(e.KeyCode)
instead of this:
vb.net Code:
txtDecimal.Text = e.KeyCode
Also, if you call the ToString with no parameters will return a string containing the enumerated value's label. If you do specify a parameter then it will not. When you call the ToString method of an integer value, which enums are, and specify "X" as the format string you'll get a hexadecimal string in upper case. That would be preferable to using the Hex Runtime function for many people, although ToString does pad to a 32-bit number with zeroes.
Re: hex + decimal keycodes utility
ok thanks. i didn't think of that
Re: hex + decimal keycodes utility
This will be usefull for APIs.