msjammu
asked on
Consume Keystroke
Hi,
VC++6 Windows:
I need some help on, how can I consume keystrokes.
Say when the user presses a Tab key if the user has pressed some other or Tab key (either holding it) and I am in the process of processing first keystroke. I want to destroy all keystoks that the user may have triggered when first key was being processed.
Many thanks
VC++6 Windows:
I need some help on, how can I consume keystrokes.
Say when the user presses a Tab key if the user has pressed some other or Tab key (either holding it) and I am in the process of processing first keystroke. I want to destroy all keystoks that the user may have triggered when first key was being processed.
Many thanks
Sorry, maybe not a good example. Try with this:
// this header is needed to use getch() and kbhit()
#include "conio.h"
int main ()
{
// some code here
int c;
c = getch(); // Wait to read first keystroke
// some processing
while (kbhit()) // verify if key exist in buffer
{ getch(); } // Read (comsume) all keystrokes triggered
// some other processing
return 0;
}
// this header is needed to use getch() and kbhit()
#include "conio.h"
int main ()
{
// some code here
int c;
c = getch(); // Wait to read first keystroke
// some processing
while (kbhit()) // verify if key exist in buffer
{ getch(); } // Read (comsume) all keystrokes triggered
// some other processing
return 0;
}
ASKER
>>VC++6 Windows:
My application is windows application MDIBased;
containing many child forms
My application is windows application MDIBased;
containing many child forms
There are many tecniques, also you can control the PreTranslateMessage event in your application.
You can filter all the WM_CHAR messages is a flag is on
Create a flag member in your CWinApp derived object:
bool m_IgnoreKeys;
Then create an event with the ClassWizard (Ctrl-W) for your app object, and control WM_CHAR specific message
(inside CYourApp::PreTranslateMess age)
if (msg==WM_CHAR) {
if (!m_IgnoreKeys) // if m_IgnoreKeys = false
return FALSE; // Do nothing
}
// else continue with pretranslatemessage
You can filter all the WM_CHAR messages is a flag is on
Create a flag member in your CWinApp derived object:
bool m_IgnoreKeys;
Then create an event with the ClassWizard (Ctrl-W) for your app object, and control WM_CHAR specific message
(inside CYourApp::PreTranslateMess
if (msg==WM_CHAR) {
if (!m_IgnoreKeys) // if m_IgnoreKeys = false
return FALSE; // Do nothing
}
// else continue with pretranslatemessage
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
c = getch(); // Wait to read first keystroke
// some processing
while (getch()) {} // Read (comsume) all keystrokes triggered
// some other processing