Click here to Skip to main content
15,899,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

I have a blank form name form1. I want whenever I press the key combination of (control+n) its shows a message ("whatever").

PLEASE MENTION CODE

Please also tell me if there any link for keyChar value of all keyboard.



Thanks
Posted
Updated 15-Sep-10 21:46pm
v2

A question asked often...
See Here[^]

For Key Chars
VB
for(int i=1; i<=255; i++)
{
char cs=(char) i;
Response.Write(i.ToString() + "--");
Response.Write(cs.ToString() + "<br>");
}
 
Share this answer
 
In the design view select your Form and go to it's properties. Select "events" and double click "KeyUp". This will add a event handler for you.

Add this code:
VB
If e.Control = True And e.KeyCode = Keys.N Then
   MsgBox("whatever")
End If


Hope this helps :)
 
Share this answer
 
You can get it in keydown event.

VB
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
  If e.KeyCode = Keys.N And e.Control Then
    MessageBox.Show("Ctrl+N is pressed", "Access Keys")
  End If
End Sub


For empty form this code is OK, but in form with controls, don't forget to set KeyPreview property of form to true.

VB
KeyPreview = True
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900