Solved

How to find the ascii values for SHIFT+ KEYS

Posted on 2001-07-26
3
498 Views
Last Modified: 2013-11-20
I want to find the acii value for the shift+keys.

 I have edit controls in my project and i want to allow the entry of
  numbers alone and "." for decimal point,so this my coding i have
  done in the pretranslatemessage().



BOOL CTrans::PreTranslateMessage(MSG* pMsg)
{
     // TODO: Add your specialized code here and/or call the base class
         
          char q[10];
           ::GetClassName(::GetFocus(),q,10);

     
      if(strcmp(q,"Edit")==0)
      {

          CWnd* ww = GetFocus();

          switch(pMsg->message)
           {
 
             case WM_KEYDOWN:
                    {
               
                 CString str;
              ww->GetWindowText(str);
        if(pMsg->wParam==190  && str.Find(".",0) ==-1)
           return  CDialog::PreTranslateMessage(pMsg);
          if(pMsg->wParam ==9 ||pMsg->wParam ==27||pMsg-
           >wParam >= 36 && pMsg->wParam <= 39 || pMsg-
           >wParam==8) return CDialog::PreTranslateMessage
           (pMsg);
                 
     if(!isdigit(pMsg->wParam))
     if(!(pMsg->wParam==46|| pMsg->wParam==8))
      return true;
     )
                 
          }
     }
     
     return CDialog::PreTranslateMessage(pMsg);
}



for the key 1 to 0 and for the . key when i use the shift keys !,@,#,$,%,^,&,*,(,),> are entered in the edit control I don't want the shift+key operation to work.

   help me regarding this.
0
Comment
Question by:vsulu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Accepted Solution

by:
migel earned 25 total points
ID: 6321320
Hi!
you can just detect than shift key pressedand bypass this key press:
if (::GetKeyState(VK_SHIFT) < 0) // key pressed
 return TRUE;
0
 
LVL 3

Assisted Solution

by:aphillips
aphillips earned 25 total points
ID: 6321956
You can avoid the problem using WM_CHAR, but here are some general ways to enhance your code:

1. Don't call GetFocus within PreTranslateMessage.  The current message is not nec. for the window with focus.

2. You allow processing of HOME (36) but not END (35).  You seem to be handling backspace in 2 places.  In fact the if statements could a bit more logically organised.

3. Use the VK_* values instead of numbers to make your code easier to read.  A few comments explaining what is being done would help too.

4. You can handle the WM_KEYDOWN message in the OnKeyDown handler rather than in PreTranslateMessage.  This is more obvious and efficient.  Your PreTranslateMessage is called for every message received by the window which could slow down mouse processing, eg. if mouse move events are being used.

5. If you handle the WM_CHAR message (in OnChar) then you don't have to worry about the SHIFT key (or tab, Escape etc) at all.  Windows does it for you.

I hope this helps.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9490558
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by : migel, aphillips (points to be split)

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question