Most keyboard keys have a constant value even when combined with different modifier keys (SHIFT, CTRL and ALT). All regular keys on the keyboard (alphabet and special characters) have a key code of their ASCII value.
Key code and key modifier values are returned in the EventRec structure. The key code can be found in EventRec.message and the key modifiers can be found in EventRec.modifiers.
Visual FoxPro interprets some keys as having a different value depending on the modifier with which they are combined. For example, if SHIFT+F10 is pressed, the corresponding fields in the EventRec would be:
-
EventRec.message = 15D (Hex)
-
EventRec.modifier = 1000 (Hex)
Similarly, if CTRL+F10 is pressed, the EventRec values would be:
-
EventRec.message = 167 (Hex)
-
EventRec.modifiers = 2000 (Hex)
When more than one modifier is used with a key, the modifier values are added together. For example, if you press CTRL+SHIFT+F10, the following values are returned:
-
EventRec.message = 167 (Hex)
-
EventRec.modifiers = 3000 (Hex)
The EventRec.modifiers value in the preceding example is 0x3000 because both the CTRL and SHIFT modifiers were included in the key press. Thus, the SHIFT key modifier (0x1000) was added to the CTRL key modifier (0x2000) to produce a value of 0x3000.
Note: |
---|
The manner in which Visual FoxPro interprets keys (specifically keys with modifiers) is inherent to Visual FoxPro. Other programs may interpret keys differently. If a key is pressed in combination with one or multiple modifier keys (SHIFT, CTRL and ALT), the uppermost nibble represents the modifiers that were used. |
The following table demonstrates that the F8 key has a different key code depending on the modifier used.
Keys pressed | Modifier | Key value of F8 |
---|---|---|
F8 |
None |
\x142 |
SHIFT+F8 |
SHIFT |
\x15B |
CTRL+F8 |
CTRL |
\x165 |
ALT+F8 |
ALT |
\x16F |
Each special key that can be combined with modifiers has a unique value when combined with each modifier. If a special key is combined with multiple modifiers, the unique value assigned to the key is its value for one of the modifiers according to the following rules:
-
First check to see if the key combination pressed includes the ALT key because the main key will be assigned its ALT key value.
-
If the key combination does not include ALT, check to see if the CTRL key modifier was used because the main key will be assigned its CTRL key value.
-
If no ALT or CTRL key modifier is used, check to see if the SHIFT key modifier was used because the main key will be assigned its SHIFT key value.
-
Finally, if no modifiers were used, the main key is assigned its value based on no modifiers.
Special Key Codes
The following table lists the key values assigned by Visual FoxPro to special keys on the keyboard.
Key | Key code (Hex) | Key modifier |
---|---|---|
LEFTMOUSE |
100 |
None |
F1 |
13B |
None |
F2 |
13C |
None |
F3 |
13D |
None |
F4 |
13E |
None |
F5 |
13F |
None |
F6 |
140 |
None |
F7 |
141 |
None |
F8 |
142 |
None |
F9 |
143 |
None |
F10 |
144 |
None |
HOME |
147 |
None |
UPARROW |
148 |
None |
PGUP |
149 |
None |
LEFTARROW |
14B |
None |
RIGHTARROW |
14D |
None |
END |
14F |
None |
DNARROW |
150 |
None |
PGDN |
151 |
None |
INS |
152 |
None |
DEL |
153 |
None |
F11 |
185 |
None |
F12 |
186 |
None |
BACKTAB |
10F |
shiftKey |
SHIFT+F1 |
154 |
shiftKey |
SHIFT+F2 |
155 |
shiftKey |
SHIFT+F3 |
156 |
shiftKey |
SHIFT+F4 |
157 |
shiftKey |
SHIFT+F5 |
158 |
shiftKey |
SHIFT+F6 |
159 |
shiftKey |
SHIFT+F7 |
15A |
shiftKey |
SHIFT+F8 |
15B |
shiftKey |
SHIFT+F9 |
15C |
shiftKey |
SHIFT+F10 |
15D |
shiftKey |
SHIFT+F11 |
187 |
shiftKey |
SHIFT+F12 |
188 |
shiftKey |
CTRL+A |
001 |
ctrlKey |
CTRL+B |
002 |
ctrlKey |
CTRL+C |
003 |
ctrlKey |
CTRL+D |
004 |
ctrlKey |
CTRL+E |
005 |
ctrlKey |
CTRL+F |
006 |
ctrlKey |
CTRL+G |
007 |
ctrlKey |
CTRL+H |
008 |
ctrlKey |
CTRL+I |
009 |
ctrlKey |
CTRL+ENTER |
00A |
ctrlKey |
CTRL+J |
00A |
ctrlKey |
CTRL+K |
00B |
ctrlKey |
CTRL+L |
00C |
ctrlKey |
CTRL+M |
00D |
ctrlKey |
CTRL+N |
00E |
ctrlKey |
CTRL+O |
00F |
ctrlKey |
CTRL+P |
010 |
ctrlKey |
CTRL+Q |
011 |
ctrlKey |
CTRL+R |
012 |
ctrlKey |
CTRL+S |
013 |
ctrlKey |
CTRL+T |
014 |
ctrlKey |
CTRL+U |
015 |
ctrlKey |
CTRL+V |
016 |
ctrlKey |
CTRL+W |
017 |
ctrlKey |
CTRL+X |
018 |
ctrlKey |
CTRL+Y |
019 |
ctrlKey |
CTRL+Z |
01A |
ctrlKey |
CTRL+LBRACKET |
01B |
ctrlKey |
CTRL+BACKSLASH |
01C |
ctrlKey |
CTRL+RBRACKET |
01D |
ctrlKey |
CTRL+CARET |
01E |
ctrlKey+shiftKey |
CTRL+HYPHEN |
01F |
ctrlKey |
CTRL+SPACEBAR |
020 |
ctrlKey |
CTRL+F1 |
15E |
ctrlKey |
CTRL+F2 |
15F |
ctrlKey |
CTRL+F3 |
160 |
ctrlKey |
CTRL+F4 |
161 |
ctrlKey |
CTRL+F5 |
162 |
ctrlKey |
CTRL+F6 |
163 |
ctrlKey |
CTRL+F7 |
164 |
ctrlKey |
CTRL+F8 |
165 |
ctrlKey |
CTRL+F9 |
166 |
ctrlKey |
CTRL+F10 |
167 |
ctrlKey |
CTRL+LEFTARROW |
173 |
ctrlKey |
CTRL+RIGHTARROW |
174 |
ctrlKey |
CTRL+END |
175 |
ctrlKey |
CTRL+PGDN |
176 |
ctrlKey |
CTRL+HOME |
177 |
ctrlKey |
CTRL+PGUP |
184 |
ctrlKey |
CTRL+F11 |
189 |
ctrlKey |
CTRL+F12 |
18A |
ctrlKey |
CTRL+UPARROW |
18D |
ctrlKey |
CTRL+DNARROW |
191 |
ctrlKey |
CTRL+INS |
192 |
ctrlKey |
CTRL+DEL |
193 |
ctrlKey |
CTRL+TAB |
194 |
ctrlKey |
ALT+Q |
110 |
altKey |
ALT+W |
111 |
altKey |
ALT+E |
112 |
altKey |
ALT+R |
113 |
altKey |
ALT+T |
114 |
altKey |
ALT+Y |
115 |
altKey |
ALT+U |
116 |
altKey |
ALT+I |
117 |
altKey |
ALT+O |
118 |
altKey |
ALT+P |
119 |
altKey |
ALT+A |
11E |
altKey |
ALT+S |
11F |
altKey |
ALT+D |
120 |
altKey |
ALT+F |
121 |
altKey |
ALT+G |
122 |
altKey |
ALT+H |
123 |
altKey |
ALT+J |
124 |
altKey |
ALT+K |
125 |
altKey |
ALT+L |
126 |
altKey |
ALT+Z |
12C |
altKey |
ALT+X |
12D |
altKey |
ALT+C |
12E |
altKey |
ALT+V |
12F |
altKey |
ALT+B |
130 |
altKey |
ALT+N |
131 |
altKey |
ALT+M |
132 |
altKey |
ALT+F1 |
168 |
altKey |
ALT+F2 |
169 |
altKey |
ALT+F3 |
16A |
altKey |
ALT+F4 |
16B |
altKey |
ALT+F5 |
16C |
altKey |
ALT+F6 |
16D |
altKey |
ALT+F7 |
16E |
altKey |
ALT+F8 |
16F |
altKey |
ALT+F9 |
170 |
altKey |
ALT+F10 |
171 |
altKey |
ALT+1 |
178 |
altKey |
ALT+2 |
179 |
altKey |
ALT+3 |
17A |
altKey |
ALT+4 |
17B |
altKey |
ALT+5 |
17C |
altKey |
ALT+6 |
17D |
altKey |
ALT+7 |
17E |
altKey |
ALT+8 |
17F |
altKey |
ALT+9 |
180 |
altKey |
ALT+0 |
181 |
altKey |
ALT+F11 |
18B |
altKey |
ALT+F12 |
18C |
altKey |
ALT+HOME |
197 |
altKey |
ALT+UPARROW |
198 |
altKey |
ALT+PGUP |
199 |
altKey |
ALT+LEFTARROW |
19B |
altKey |
ALT+RIGHTARROW |
19D |
altKey |
ALT+END |
19F |
altKey |
ALT+DNARROW |
1A0 |
altKey |
ALT+PGDN |
1A1 |
altKey |
ALT+INS |
1A2 |
altKey |
ALT+DEL |
1A3 |
altKey |
Example
В | Copy Code |
---|---|
FAR EventHandler(WHandle theWindow, EventRec FAR *ev) { switch(ev->what) { case keyDownEvent: /* Check the keyDownEvent */ if (ev->modifiers & shiftCodeMask) /* A modifier was pressed. */ { if (ev->modifiers & altKey) /* Check for the ALT Key */ _PutStr("ALT Key Code should be used.\n"); else if (ev->modifiers & ctrlKey) /* CTRL Key */ _PutStr("CTRL Key Code should be used.\n"); else if (ev->modifiers & shiftKey) /* SHIFT Key */ _PutStr("SHIFT Key Code should be used.\n"); } else _PutStr("Regular Key Code should be used.\n"); return NO; /* Let Visual FoxPro have Key also */ break; default: return NO; } } |
Note: |
---|
shiftCodeMask, altKey, ctrlKey, and shiftKey are all defined in PRO_EXT.H and PRO_EXT.INC as follows: |
-
#define shiftCodeMask 0xf000
-
#define shiftKey 0x1000
-
#define ctrlKey 0x2000
-
#define altKey 0x4000