Using KeyPreview to handle form shortcut keys

31 10 2008

If you need to trap shortcut keys in your application to perform misc tasks, use the following code to set KeyPreview to true and then in the KeyDown event handle the actual clicks:

 private void Form_OnLoad(object sender, EventArgs e)
{
KeyPreview
= true;
}

private void form_KeyDown(object sender, KeyEventArgs e)
{

if (e.Alt && e.KeyCode.ToString() == “L”)
{

//DO Something            
}
}

Advertisements

Actions

Information

2 responses

9 01 2009
sivasakthi

nice…
searching for the form control shorcuts..
good….Thanks..

9 01 2009
simonsteed

Quick google search pulled up the following:

0 (null) 64 @ 128 Ç 192 À
1 1 65 A 129 ü 193 Á
2 2 66 B 130 é 194 194
3 3 67 C 131 â 195 195
4 4 68 D 132 ä 196 196
5 5 69 E 133 à 197 197
6 6 70 F 134 å 198 198
7 7 71 G 135 ç 199 199
8 8 72 H 136 ê 200 200
9 (tab) 73 I 137 ë 201 201
10 10 74 J 138 è 202 202
11 (home) 75 K 139 ï 203 203
12 (form feed) 76 L 140 î 204 204
13 (carr. return) 77 M 141 ì 205 205
14 14 78 N 142 Ä 206 206
15 15 79 O 143 Å 207 207
16 16 80 P 144 É 208 208
17 17 81 Q 145 æ 209 209
18 18 82 R 146 Æ 210 210
19 19 83 S 147 ô 211 211
20 ¶ 84 T 148 ö 212 212
21 § 85 U 149 ò 213 213
22 22 86 V 150 û 214 214
23 23 87 W 151 ù 215 215
24 (cancel) 88 X 152 ÿ 216 216
25 (end medium) 89 Y 153 Ö 217 217
26 26 90 Z 154 Ü 218 218
27 27 91 [ 155 ¢ 219 219
28 28 92 \ 156 £ 220 220
29 29 93 ] 157 ¥ 221 221
30 30 94 ^ 158 158 222 222
31 31 95 _ 159 159 223 223
32 (blank) 96 ` 160 á 224 à
33 ! 97 a 161 í 225 ß
34 ” 98 b 162 ó 226 â
35 # 99 c 163 ú 227 ã
36 $ 100 d 164 ñ 228 228
37 % 101 e 165 Ñ 229 229
38 & 102 f 166 ª 230 µ
39 ‘ 103 g 167 º 231 231
40 ( 104 h 168 ¿ 232 232
41 ) 105 i 169 169 233 233
42 * 106 j 170 ¬ 234 234
43 + 107 k 171 ½ 235 235
44 , 108 l 172 ¼ 236 236
45 – 109 m 173 ¡ 237 237
46 . 110 n 174 « 238 238
47 / 111 o 175 » 239 239
48 0 112 p 176 ° 240 240
49 1 113 q 177 ± 241 ±
50 2 114 r 178 ² 242 ò
51 3 115 s 179 ³ 243 ó
52 4 116 t 180 ´ 244 ô
53 5 117 u 181 µ 245 245
54 6 118 v 182 ¶ 246 ÷
55 7 119 w 183 · 247 247
56 8 120 x 184 ¸ 248 °
57 9 121 y 185 ¹ 249 ·
58 : 122 z 186 º 250 ·
59 ; 123 { 187 » 251 251
60 126 ~ 190 ¾ 254 254
63 ? 127  191 ¿ 255 (blank)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: