keyboard key event
-
Hi all, In my design, i should display the individual character which are keyed in by the user into the combobox. lets say user need to key in the word "HELLO" in the combobox. if the user press "H", one message box should show the letter "H". the same way for all other letters. So, How do i get the individual character which has been keyed in using the keyboard? Thanks in Advance. Regards, Ram
When u press a key in the combobox the message actually goes to the edit control inside the combo box. To trap that event u can do like this. 1 Create a member variable for the combobox say m_ComboBox; 2. Now overide the PreTranslateMessage function of the dialog; 3. in that funtion write like this
BOOL CTest::PreTranslateMessage(MSG* pMsg) { if( WM_KEYDOWN == pMsg->message ) { if( ::GetParent( pMsg->hwnd ) == m_combo.m_hWnd ) { TCHAR tcChar[2] = {0}; tcChar[0] = pMsg->wParam; AfxMessageBox( tcChar ); } } return CDialog::PreTranslateMessage(pMsg); }
nave -
When u press a key in the combobox the message actually goes to the edit control inside the combo box. To trap that event u can do like this. 1 Create a member variable for the combobox say m_ComboBox; 2. Now overide the PreTranslateMessage function of the dialog; 3. in that funtion write like this
BOOL CTest::PreTranslateMessage(MSG* pMsg) { if( WM_KEYDOWN == pMsg->message ) { if( ::GetParent( pMsg->hwnd ) == m_combo.m_hWnd ) { TCHAR tcChar[2] = {0}; tcChar[0] = pMsg->wParam; AfxMessageBox( tcChar ); } } return CDialog::PreTranslateMessage(pMsg); }
naveif i do this, i couldnt able to get the output. the project is comiled and exectued, but there is no output and comeback to the project workspace again. Y is it like this? Thanks. Regards, Ram
-
if i do this, i couldnt able to get the output. the project is comiled and exectued, but there is no output and comeback to the project workspace again. Y is it like this? Thanks. Regards, Ram
-
yes,My application is dialog based. it has only one combobox, nothing more than that. Jus i need to display the characters which has been key-in by the user into the combobox. Regards, Ram
-
Can u plz explain with some code. I tried to use ON_WM_KEYDOWN. But i douldnt get it. Thanx. Regards, Ram
Ram Murali wrote:
Can u plz explain with some code. I tried to use ON_WM_KEYDOWN. But i douldnt get it.
have you added that between BEGIN_MESSAGE_MAP and END_MESSAGE_MAP
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You
-
yes,My application is dialog based. it has only one combobox, nothing more than that. Jus i need to display the characters which has been key-in by the user into the combobox. Regards, Ram
-
Ram Murali wrote:
Can u plz explain with some code. I tried to use ON_WM_KEYDOWN. But i douldnt get it.
have you added that between BEGIN_MESSAGE_MAP and END_MESSAGE_MAP
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You
Ya i have added that in between BEGIN_MESSAGE_MAP and END_MESSAGE_MAP. Regards, Ram
-
i hope u have created the m_combo variable and mapped the PreTranslateMessage message using the class wizard. isn't it? did u tried puting breakpoint in the PreTranslateMessage fnuction? nave
Ya u r correct. I used breakpoint also. Still i couldnt get the output window. I put breakpoint in OnInitDialog and PreTranslateMessage. once i press debug button, it directly goes to pretanslatemessage function and then goes to the end of the program. since i dun input any char if( WM_KEYDOWN == pMsg->message ) becomes false. so it goes to the end of the pretanslate function. in this case i can see the minimized window in the taskbar. but i couldnt maximize it. eventually i couldnt see the output window. :( Regards, Ram
-
Ya i have added that in between BEGIN_MESSAGE_MAP and END_MESSAGE_MAP. Regards, Ram
Ram Murali wrote:
Ya i have added that in between BEGIN_MESSAGE_MAP and END_MESSAGE_MAP.
Sorry if my question look childish, Have you added OnKeyDown function plus What is your base class for your window program
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You
-
Ram Murali wrote:
Ya i have added that in between BEGIN_MESSAGE_MAP and END_MESSAGE_MAP.
Sorry if my question look childish, Have you added OnKeyDown function plus What is your base class for your window program
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You
:(Yes i did that too. Regards, Ram
-
Ya u r correct. I used breakpoint also. Still i couldnt get the output window. I put breakpoint in OnInitDialog and PreTranslateMessage. once i press debug button, it directly goes to pretanslatemessage function and then goes to the end of the program. since i dun input any char if( WM_KEYDOWN == pMsg->message ) becomes false. so it goes to the end of the pretanslate function. in this case i can see the minimized window in the taskbar. but i couldnt maximize it. eventually i couldnt see the output window. :( Regards, Ram
-
Ram Murali wrote:
Ya i have added that in between BEGIN_MESSAGE_MAP and END_MESSAGE_MAP.
Sorry if my question look childish, Have you added OnKeyDown function plus What is your base class for your window program
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You
ThatsAlok wrote:
OnKeyDown
r u saying that u can get the key down event in the combobox just by doing like this. the WM_KEYDOWN message goes to the edit control inside the combobox. It cannot be mapped like this from the dialog class, nor from a class drived from CCcomboBox nave
-
BOOL CTest::PreTranslateMessage(MSG* pMsg) { if( WM_KEYDOWN == pMsg->message ) { if( ::GetParent( pMsg->hwnd ) == m_combo.m_hWnd ) { TCHAR tcChar[2] = {0}; tcChar[0] = pMsg->wParam; AfxMessageBox( tcChar ); } } return CTest::PreTranslateMessage(pMsg); } Regards, Ram
-
BOOL CTest::PreTranslateMessage(MSG* pMsg) { if( WM_KEYDOWN == pMsg->message ) { if( ::GetParent( pMsg->hwnd ) == m_combo.m_hWnd ) { TCHAR tcChar[2] = {0}; tcChar[0] = pMsg->wParam; AfxMessageBox( tcChar ); } } return CTest::PreTranslateMessage(pMsg); } Regards, Ram
-
Ram Murali wrote:
return CTest::PreTranslateMessage(pMsg);
here lies the problem it should be like this CDialog::PreTranslateMessage(pMsg); nave
wow. thats gr8. But now i can able to key-in only one character. cannot key-in more than one char.:( Thanx for spending ur time for me. Thanx a lot. Regards, Ram
-
wow. thats gr8. But now i can able to key-in only one character. cannot key-in more than one char.:( Thanx for spending ur time for me. Thanx a lot. Regards, Ram
-
ThatsAlok wrote:
OnKeyDown
r u saying that u can get the key down event in the combobox just by doing like this. the WM_KEYDOWN message goes to the edit control inside the combobox. It cannot be mapped like this from the dialog class, nor from a class drived from CCcomboBox nave
Naveen R wrote:
u saying that u can get the key down event in the combobox just by doing like this. the WM_KEYDOWN message goes to the edit control inside the combobox.
I believe you havn't read my question carefully!, after reading your discussion with the PP(Problem Poster), i come to know he need to implement that for Combo Box!
Naveen R wrote:
t cannot be mapped like this from the dialog class, nor from a class drived from CCcomboBox
Really do you need my comment on this?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You
-
Let me explain my objective briefly. I need to desing combobox in such a way tat user can only enter the character "D", "I" and "0-9", in the combobox. If a user enters other character than the above specified, it should not be displayed in the Combobox. and the maximum no of character user can enter is only 5. this is my objective. with the current code, i can only enter one character. if i press the other character, the new one replaces the old character in the combobox. lets say i wannu enter "HELLO" if i press "H" message box shows H. then if i enter I, this I replace the H in the combobox. :(:^) again thanx a lot for ur spending ur valuable time for me. Regards, Ram
-
wow. thats gr8. But now i can able to key-in only one character. cannot key-in more than one char.:( Thanx for spending ur time for me. Thanx a lot. Regards, Ram
Ram Murali wrote:
ut now i can able to key-in only one character. cannot key-in more than one char.:(
create a string there only!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You
-
Naveen R wrote:
u saying that u can get the key down event in the combobox just by doing like this. the WM_KEYDOWN message goes to the edit control inside the combobox.
I believe you havn't read my question carefully!, after reading your discussion with the PP(Problem Poster), i come to know he need to implement that for Combo Box!
Naveen R wrote:
t cannot be mapped like this from the dialog class, nor from a class drived from CCcomboBox
Really do you need my comment on this?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You