May 07, 2024, 09:28:54 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


help with the OnKeyDown Cwindow method

Started by Haim, March 04, 2006, 12:13:14 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Haim

As far as I understand, the unsigned Int nFlags,(the third argument in the OnKeyDown method) contains info about the state of special keys such as Shift keys, Control Keys etc.
is this correct? If so, how do I decode the values to get the info?
It seems that the value of nFlags changes with every kepress in a manner I cannot understand. Can anyone shed some light on this?

Ionic Wind Support Team

No. The values are packed by Windows into a bitfield.  Here is a table from MSDN

Quote
Bit Description
0â€ââ,¬Å"7
Scan code (OEM-dependent value).

8
Extended key, such as a function key or a key on the numeric keypad (1 if it is an extended key).

9â€ââ,¬Å"10
Not used.

11â€ââ,¬Å"12
Used internally by Windows.

13
Context code (1 if the ALT key is held down while the key is pressed; otherwise 0).

14
Previous key state (1 if the key is down before the call, 0 if the key is up).

15
Transition state (1 if the key is being released, 0 if the key is being pressed).

The first parameter is what you want.  OnKeyDown gets called for function keys, control, etc.  The virtual key code is sent in the nChar parameter.

If you are looking for key combinations then use OnChar in conjunction with GetKeyState.

IF(GetKeyState(0x11))
{
   // Control key is pressed.
}

Here are all the virtual key codes, in hex.

Quote
Value (hexadecimal) Mouse or keyboard equivalent
01 Left mouse button
02 Right mouse button
03 Control-break processing
04 Middle mouse button (three-button mouse)
05-07 Undefined
08 BACKSPACE key
09 TAB key
0A-0B Undefined
0C CLEAR key
0D ENTER key
0E-0F Undefined
10 SHIFT key
11 CTRL key
12 ALT key
13 PAUSE key
14 CAPS LOCK key
15-19 Reserved for Kanji systems
1A Undefined
1B ESC key
1C-1F Reserved for Kanji systems
20 SPACEBAR
21 PAGE UP key
22 PAGE DOWN key
23 END key
24 HOME key
25 LEFT ARROW key
26 UP ARROW key
27 RIGHT ARROW key
28 DOWN ARROW key
29 SELECT key
2A Original equipment manufacturer (OEM) specific
2B EXECUTE key
2C PRINT SCREEN key for Windows 3.0 and later
2D INS key
2E DEL key
2F HELP key
30 0 key
31 1 key
32 2 key
33 3 key
34 4 key
35 5 key
36 6 key
37 7 key
38 8 key
39 9 key
3A-40 Undefined
41 A key
42 B key
43 C key
44 D key
45 E key
46 F key
47 G key
48 H key
49 I key
4A J key
4B K key
4C L key
4D M key
4E N key
4F O key
50 P key
51 Q key
52 R key
53 S key
54 T key
55 U key
56 V key
57 W key
58 X key
59 Y key
5A Z key
5B Left Windows key (Microsoft Natural Keyboard)
5C Right Windows key (Microsoft Natural Keyboard)
5D Applications key (Microsoft Natural Keyboard)
5E-5F Undefined
60 Numeric keypad 0 key
61 Numeric keypad 1 key
62 Numeric keypad 2 key
63 Numeric keypad 3 key
64 Numeric keypad 4 key
65 Numeric keypad 5 key
66 Numeric keypad 6 key
67 Numeric keypad 7 key
68 Numeric keypad 8 key
69 Numeric keypad 9 key
6A Multiply key
6B Add key
6C Separator key
6D Subtract key
6E Decimal key
6F Divide key
70 F1 key
71 F2 key
72 F3 key
73 F4 key
74 F5 key
75 F6 key
76 F7 key
77 F8 key
78 F9 key
79 F10 key
7A F11 key
7B F12 key
7C F13 key
7D F14 key
7E F15 key
7F F16 key
80H F17 key
81H F18 key
82H F19 key
83H F20 key
84H F21 key
85H F22 key
86H F23 key
87H F24 key
88-8F Unassigned
90 NUM LOCK key
91 SCROLL LOCK key
92-B9 Unassigned
BA-C0 OEM specific
C1-DA Unassigned
DB-E4 OEM specific
E5 Unassigned
E6 OEM specific
E7-E8 Unassigned
E9-F5 OEM specific
F6 Attn key
F7 CrSel key
F8 ExSel key
F9 Erase EOF key
FA Play key
FB Zoom key
FC Reserved for future use.
FD PA1 key
FE Clear key

Ionic Wind Support Team