Answered by:
get key names in vb.net

Question
-
hello every one i am trying to make an application to get keyboard keys names but i did confused on [ this key. can anyone tell me what is the name of [ key on vb.netFriday, May 8, 2015 8:07 AM
Answers
-
Inspired by Armin I made this code which makes it very easy.
Public Class Form1 Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown Text = e.KeyData.ToString End Sub End Class
Success
Cor- Marked as answer by repulsive1 Friday, May 15, 2015 5:13 PM
Friday, May 8, 2015 11:13 AM -
>left square" bracket or "bracketleft"
Be aware VB has no keyboard names.
Classes for instance Windows Forms Controls can have that used in the events and are related to the keyvalue which is returned.
On my US English keyboard the
The code = oem4
the keydata = OEMOpenBrackets
The value is 219
Success
Cor
- Edited by Cor Ligthert Friday, May 8, 2015 11:12 AM
- Proposed as answer by Reed KimbleMVP Saturday, May 9, 2015 4:49 PM
- Marked as answer by repulsive1 Friday, May 15, 2015 5:12 PM
Friday, May 8, 2015 8:15 AM -
Add this to the default Form of a new project:
Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs) MyBase.OnKeyDown(e) Debug.WriteLine(e.KeyCode.ToString) End Sub
Start it and press keys. In the Debug window, you will see the keys as they are named as part of the System.Windows.Forms.Keys enumeration.
Armin
- Edited by Armin Zingler Friday, May 8, 2015 10:28 AM
- Marked as answer by repulsive1 Friday, May 15, 2015 5:13 PM
Friday, May 8, 2015 10:28 AM -
You can try this. If a keyboard key provides a character then the character will be displayed in the TextBox. The information about the key selected is always provided in the Label.
Note that the Label displays a key and any function key selected prior to that key even though the function key selected appears after the selected keyboard key separated by a comma. An "A" in the Label is always upper case but in the TextBox is the actual case used. But in the Label it advises if Shift is selected for upper shifted characters. However if Caps Lock (called CAPITALS I think) is selected that information displays in the Label but once a letter is selected while Caps Lock is on the character is upper case in both the Label and TextBox. Caps Lock displays again in the Label when it is selected again to turn it off.
Update: This will not detect the Fn key being selected on the keyboard.
Option Strict On Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2))) Label1.Text = "Waiting" End Sub Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean If TextBox1.Text.Count > 0 Then Try TextBox1.Text = TextBox1.Text.Remove(0, 1) Catch ex As Exception End Try End If Label1.Text = keyData.ToString & vbCrLf & vbCrLf & msg.ToString Return Nothing End Function End Class
http://www.computerhope.com/keys.htm
Key/Symbol - Explanation
Windows - PC keyboards have a Windows key, which looks like a four-pane window
Command - Apple Mac computers have a command key.
Esc - Esc (Escape) key
F1 to F12 - Information about the F1 through F12 keyboard keys.
F13 to F24 - Information about the F13 through F24 keyboard keys.
Tab - Tab key
Caps lock - Caps lock key
Shift - Shift key
Ctrl - Ctrl (Control) key
Fn - Fn (Function) key
Alt - Alt (Alternate) key (PC Only; Mac users have Option key)
Spacebar - Spacebar key
Arrows - Up, Down, Left, Right Arrow keys
Back Space - Back space (or Backspace) key
Delete - Delete or Del key
Enter - Enter key
Prt Scrn - Print screen key
Scroll lock - Scroll lock key
Pause - Pause key
Break - Break key
Insert - Insert key
Home - Home key
Page up - Page up or pg up key
Page down - Page down or pg dn key
End - End key
Num Lock - Num Lock key
~ - Tilde
` - Acute, Back quote, grave, grave accent, left quote, open quote, or a push
! - Exclamation mark, Exclamation point, or Bang
@ - Ampersat, Arobase, Asperand, At, or At symbol
# - Octothorpe, Number, Pound, sharp, or Hash
£ - Pounds Sterling or Pound symbol
€ - Euro
$ - Dollar sign or generic currency
¢ - Cent sign
¥ - Chinese Yuan
§ - Micro or Section
% - Percent
° - Degree
^ - Caret or Circumflex
& - Ampersand, Epershand, or And
* - Asterisk and sometimes referred to as star.
( - Open parenthesis
) - Close parenthesis
- - Hyphen, Minus or Dash
_ - Underscore
+ - Plus
= - Equals
{ - Open Brace, squiggly brackets, or curly bracket
} - Close Brace, squiggly brackets, or curly bracket
[ - Open bracket
] - Close bracket
| - Pipe, Or, or Vertical bar
\ - Backslash or Reverse Solidus
/ - Forward slash, Solidus, Virgule, or Whack
: - Colon
; - Semicolon
" - Quote, Quotation mark, or Inverted commas
' - Apostrophe or Single Quote
< - Less Than or Angle brackets
> - Greater Than or Angle brackets
, - Comma
. - Period, dot or Full Stop
? - Question Mark
La vida loca
- Edited by Mr. Monkeyboy Saturday, May 9, 2015 5:59 AM
- Marked as answer by repulsive1 Friday, May 15, 2015 5:13 PM
Saturday, May 9, 2015 5:49 AM -
as noted:
[] = Brackets (open/close), or, less commonly Square-Brace
{} = Braces (open/close)
Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
- Marked as answer by repulsive1 Friday, May 15, 2015 5:13 PM
Saturday, May 9, 2015 4:51 PM
All replies
-
>left square" bracket or "bracketleft"
Be aware VB has no keyboard names.
Classes for instance Windows Forms Controls can have that used in the events and are related to the keyvalue which is returned.
On my US English keyboard the
The code = oem4
the keydata = OEMOpenBrackets
The value is 219
Success
Cor
- Edited by Cor Ligthert Friday, May 8, 2015 11:12 AM
- Proposed as answer by Reed KimbleMVP Saturday, May 9, 2015 4:49 PM
- Marked as answer by repulsive1 Friday, May 15, 2015 5:12 PM
Friday, May 8, 2015 8:15 AM -
Add this to the default Form of a new project:
Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs) MyBase.OnKeyDown(e) Debug.WriteLine(e.KeyCode.ToString) End Sub
Start it and press keys. In the Debug window, you will see the keys as they are named as part of the System.Windows.Forms.Keys enumeration.
Armin
- Edited by Armin Zingler Friday, May 8, 2015 10:28 AM
- Marked as answer by repulsive1 Friday, May 15, 2015 5:13 PM
Friday, May 8, 2015 10:28 AM -
Inspired by Armin I made this code which makes it very easy.
Public Class Form1 Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown Text = e.KeyData.ToString End Sub End Class
Success
Cor- Marked as answer by repulsive1 Friday, May 15, 2015 5:13 PM
Friday, May 8, 2015 11:13 AM -
You can try this. If a keyboard key provides a character then the character will be displayed in the TextBox. The information about the key selected is always provided in the Label.
Note that the Label displays a key and any function key selected prior to that key even though the function key selected appears after the selected keyboard key separated by a comma. An "A" in the Label is always upper case but in the TextBox is the actual case used. But in the Label it advises if Shift is selected for upper shifted characters. However if Caps Lock (called CAPITALS I think) is selected that information displays in the Label but once a letter is selected while Caps Lock is on the character is upper case in both the Label and TextBox. Caps Lock displays again in the Label when it is selected again to turn it off.
Update: This will not detect the Fn key being selected on the keyboard.
Option Strict On Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2))) Label1.Text = "Waiting" End Sub Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean If TextBox1.Text.Count > 0 Then Try TextBox1.Text = TextBox1.Text.Remove(0, 1) Catch ex As Exception End Try End If Label1.Text = keyData.ToString & vbCrLf & vbCrLf & msg.ToString Return Nothing End Function End Class
http://www.computerhope.com/keys.htm
Key/Symbol - Explanation
Windows - PC keyboards have a Windows key, which looks like a four-pane window
Command - Apple Mac computers have a command key.
Esc - Esc (Escape) key
F1 to F12 - Information about the F1 through F12 keyboard keys.
F13 to F24 - Information about the F13 through F24 keyboard keys.
Tab - Tab key
Caps lock - Caps lock key
Shift - Shift key
Ctrl - Ctrl (Control) key
Fn - Fn (Function) key
Alt - Alt (Alternate) key (PC Only; Mac users have Option key)
Spacebar - Spacebar key
Arrows - Up, Down, Left, Right Arrow keys
Back Space - Back space (or Backspace) key
Delete - Delete or Del key
Enter - Enter key
Prt Scrn - Print screen key
Scroll lock - Scroll lock key
Pause - Pause key
Break - Break key
Insert - Insert key
Home - Home key
Page up - Page up or pg up key
Page down - Page down or pg dn key
End - End key
Num Lock - Num Lock key
~ - Tilde
` - Acute, Back quote, grave, grave accent, left quote, open quote, or a push
! - Exclamation mark, Exclamation point, or Bang
@ - Ampersat, Arobase, Asperand, At, or At symbol
# - Octothorpe, Number, Pound, sharp, or Hash
£ - Pounds Sterling or Pound symbol
€ - Euro
$ - Dollar sign or generic currency
¢ - Cent sign
¥ - Chinese Yuan
§ - Micro or Section
% - Percent
° - Degree
^ - Caret or Circumflex
& - Ampersand, Epershand, or And
* - Asterisk and sometimes referred to as star.
( - Open parenthesis
) - Close parenthesis
- - Hyphen, Minus or Dash
_ - Underscore
+ - Plus
= - Equals
{ - Open Brace, squiggly brackets, or curly bracket
} - Close Brace, squiggly brackets, or curly bracket
[ - Open bracket
] - Close bracket
| - Pipe, Or, or Vertical bar
\ - Backslash or Reverse Solidus
/ - Forward slash, Solidus, Virgule, or Whack
: - Colon
; - Semicolon
" - Quote, Quotation mark, or Inverted commas
' - Apostrophe or Single Quote
< - Less Than or Angle brackets
> - Greater Than or Angle brackets
, - Comma
. - Period, dot or Full Stop
? - Question Mark
La vida loca
- Edited by Mr. Monkeyboy Saturday, May 9, 2015 5:59 AM
- Marked as answer by repulsive1 Friday, May 15, 2015 5:13 PM
Saturday, May 9, 2015 5:49 AM -
as noted:
[] = Brackets (open/close), or, less commonly Square-Brace
{} = Braces (open/close)
Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
- Marked as answer by repulsive1 Friday, May 15, 2015 5:13 PM
Saturday, May 9, 2015 4:51 PM