Hey, I'm trying to get input for my program from the keyboard. I'm used to using GetAsyncKeyState(//) which seems like a good way to do things. But, I want my program to detect for pressed keys outside of a timer, preferably using the message loop.
I've been looking at:
AndCode://ON_WM_KEYDOWN( ) afx_msg void OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags );
Msdn states I should call OnChar after OnKeyDown function to get the pressed character. But I dont get how this works. Do I add WM_KEYDOWN to my messaging loop, call OnKeyDown then OnChar? Also, how do I fill out nFlags?Code://ON_WM_CHAR( ) afx_msg void OnChar( UINT nChar, UINT nRepCnt, UINT nFlags );
"For a WM_KEYDOWN message..." (Shown in the bottom of the above quote) I dont get how you'd set bit 15 to 0. (Scan code | 15(0) | 13(0))... I know thats completely off though >.>.'**OnKeyDown**
Specifies the virtual key code of the given key. For a list of of standard virtual key codes, see Winuser.h
Repeat count (the number of times the keystroke is repeated as a result of the user holding down the key).
Specifies the scan code, key-transition code, previous key state, and context code, as shown in the following list: Value 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).
For a WM_KEYDOWN message, the key-transition bit (bit 15) is 0 and the context-code bit (bit 13) is 0.
Once again, I'm lost as to what to set the parameters of this.**OnChar**
Contains the character code value of the key.
Contains the repeat count, the number of times the keystroke is repeated when user holds down the key.
Contains the scan code, key-transition code, previous key state, and context code, as shown in the following list: Value Meaning
0-15 Specifies the repeat count. The value is the number of times the keystroke is repeated as a result of the user holding down the key.
16-23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM)
24 Specifies whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0.
25-28 Used internally by Windows.
29 Specifies the context code. The value is 1 if the ALT key is held down while the key is pressed; otherwise, the value is 0.
30 Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is 0 if the key is up.
31 Specifies the transition state. The value is 1 if the key is being released, or it is 0 if the key is being pressed.
And one last thing, why call OnKeyDown then OnChar if you need to specify a certain key for OnKeyDown. It could just as easily return a boolean and there would be no need for OnChar. Yet, it returns a ?afx_msg? or does it return void? The function announcement is confusing.