Link to home
Start Free TrialLog in
Avatar of msjammu
msjammuFlag for United States of America

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
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

That will depend what kind of applications are you building: console, Win32, MFC. But a generica aproach is something like this:

c = getch();   // Wait to read first keystroke
// some processing
while (getch()) {}  // Read (comsume) all keystrokes triggered
// some other processing

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;
}
Avatar of msjammu

ASKER

>>VC++6 Windows:
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::PreTranslateMessage)
   if (msg==WM_CHAR) {
       if (!m_IgnoreKeys)        // if m_IgnoreKeys = false
            return FALSE;          // Do nothing
   }
// else continue with pretranslatemessage


ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial