How to get char value from WM_KEYDOWN ? 
Author Message
 How to get char value from WM_KEYDOWN ?

Look at ToAscii() and ToAsciiEx() functions in Platform
SDK.

Binoy

Quote:
>-----Original Message-----
>Hi,
>     In one of my projects, I have to deal with

WM_KEYDOWN. The requirement
Quote:
>is that I should be able to know which character the
user typed. But you
>know, the parameter goes along with WM_KEYDOWN is the

virtual key code . How
Quote:
>can I translate virtual key code to the actual char

value? I have tried some
Quote:
>method, but it seems they all have some kind of
limitation.

>     I have used

>1. TranslateMessage:
>....
>   MSG msg;
>   if(TranslateMessage(lpMsg))
>   {
>    if(PeekMessage

(&msg,NULL,WM_KEYFIRST,WM_KEYLAST,PM_REMOVE))
Quote:
>    {
>       if

(msg.message==WM_CHAR&&msg.wParam>=0x20&&msg.wParam<=0x7e)
Quote:
>         g_TypedStr+=(char)msg.wParam;
>       else
>        return S_FALSE;
>    }
>    else return FALSE;
>   }
>....
>    Using above codes, I can get the right char value

but the arrow key will
Quote:
>be non-function in the application. I don't know why.

>2. MapVirtualKey
>    Like what MSDN says, this function can not provide

shifted char value .
Quote:
>':' will be read as ';' .

>   Any other way to do this job ? For some reason, I can
not catch WM_CHAR
>in this application.

>Waiting for your comments

>Jeff

>.



Tue, 26 Apr 2005 08:45:02 GMT  
 How to get char value from WM_KEYDOWN ?
Hi,
     In one of my projects, I have to deal with WM_KEYDOWN. The requirement
is that I should be able to know which character the user typed. But you
know, the parameter goes along with WM_KEYDOWN is the virtual key code . How
can I translate virtual key code to the actual char value? I have tried some
method, but it seems they all have some kind of limitation.

     I have used

1. TranslateMessage:
...
   MSG msg;
   if(TranslateMessage(lpMsg))
   {
    if(PeekMessage(&msg,NULL,WM_KEYFIRST,WM_KEYLAST,PM_REMOVE))
    {
       if(msg.message==WM_CHAR&&msg.wParam>=0x20&&msg.wParam<=0x7e)
         g_TypedStr+=(char)msg.wParam;
       else
        return S_FALSE;
    }
    else return FALSE;
   }
...
    Using above codes, I can get the right char value but the arrow key will
be non-function in the application. I don't know why.

2. MapVirtualKey
    Like what MSDN says, this function can not provide shifted char value .
':' will be read as ';' .

   Any other way to do this job ? For some reason, I can not catch WM_CHAR
in this application.

Waiting for your comments

Jeff



Tue, 26 Apr 2005 08:27:47 GMT  
 How to get char value from WM_KEYDOWN ?

Quote:
>     In one of my projects, I have to deal with WM_KEYDOWN. The requirement
>is that I should be able to know which character the user typed. But you
>know, the parameter goes along with WM_KEYDOWN is the virtual key code . How
>can I translate virtual key code to the actual char value?

Jeff,

Try the ToAsciiEx API.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq



Tue, 26 Apr 2005 09:24:46 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. getting the asci value of a char

2. How can I transform a int value to a char value

3. getting WM_KEYDOWN from a ComboBox

4. Getting WM_KEYDOWN in a Dialog box app

5. Getting Last 3 Chars of Char*

6. Turning hex values in a char array to character equivilants

7. converting char bit value to int

8. Adding char string values

9. Converting LONG value to CHAR array

10. assigning the value of a char to a string (newbie)

11. ascii values of chars

12. Empty char values?

 

 
Powered by phpBB® Forum Software