Trapping Key input in a VC++ dialog

I know that the wm_char function is called when you type a key in a dialog. However I want to open a messagebox or a new dialog when the user has pressed a certain sequence of keys e.g abc

is this possible , what functions check for these any comments / code examples would be super.

Cheers
LK--<
LizardKingAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

inprasCommented:
Hi LizardKing
There is no function available to check for serial keys pressed or serial activities done even easter egg like softwares will also store the events or combinations in an array (or sort of) and comare with the required sequence
U also have to do the same thing.

Regards
0
LizardKingAuthor Commented:
Thats not an answer thats a comment

but thanx anyway

I will do a bit more research

Cheers

LK--<
0
mikeblasCommented:
Do you want sample code?

..B ekiM
0
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

basantCommented:
But WM_CHAR will not be posted to Dialog when any of the Child has the focus. In that case what is your requirement.

Can't you create an Edit Box where you enter the input sequence and then do what u want.
0
LizardKingAuthor Commented:
Mike B

Sample code would be helpful. I have got it working with the
PreTranslateMessage(MSG* pMsg)
function , then I check if
if(pMsg->message==WM_KEYDOWN && pMsg->wParam==65){
This traps the A key being pressed
however if you have another way sample code would be great...

Thanx

basant
I do have an edit control on one of my dialogs however I wanted to try and trap keypresses without using an edit box.......

Thanx anyhoo


LK--<
0
basantCommented:
BOOL CheckPassword(WPARAM wParam)
{
      char* szPassword = "XOMGROL";
      if( (g_lpMapView->m_szCharCount >=0 ) && (g_lpMapView->m_szCharCount <7))
      {
            if(wParam == (WPARAM) (szPassword[g_lpMapView->m_szCharCount]))
            {
                  ++g_lpMapView->m_szCharCount;
                  if(g_lpMapView->m_szCharCount == 7)
                  {
                        g_lpMapView->m_szCharCount = 0;
                        return TRUE;
                  }
            }
            else
                  g_lpMapView->m_szCharCount = 0;
      }
}

// The following pseudo code might be useful for you. This checks for certain password sequence. Returns TRUE if it matches.
0
abdijCommented:
Here is the peice of code that captures the keys pressed when the dialog is in focus

BOOL CCaptureKeysDlg::PreTranslateMessage(MSG* pMsg)
{

      switch(pMsg->message)
      {
      case WM_CHAR:
            {
                  if(m_nPsswdIndex >= 100)
                        return FALSE;

                  m_szPsswd[m_nPsswdIndex++] = (char)pMsg->wParam;
                  if(strcmpi(m_szPsswd,"abdij") == 0)
                        AfxMessageBox("You have hit the Magic Box");
                  break;
            }
      }

      return CDialog::PreTranslateMessage(pMsg);
}

Here the m_szPsswd is a character buffer of 100 and m_nPsswdIndex is an UINT member variable of the dialog.

Here is what you need to do:

1> For the dialog which needs to capture the keys map the "PreTranslateMessage" function using the Class Wizard (VC++ 5.0 or 6.0).

2> In the "PreTranslateMessage" add the code similar to the one i have shown above. My code works for the string "abdij". Change your string suitably.

3> String compare and pop and Dialog or Message Box like i have done.

You can contact me if you need the whole code.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LizardKingAuthor Commented:
I like it , I did however use the PreTranslateMessage already I just checked for WM_KEYDOWN and used flags and ASCII values to check for key input , I havent tryed your way but it does look correct
Thanx

You get the points

LK--<
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.