How to convert virtual key code to character code?

2019-04-12 21:41发布

In the onkeydown() handler I am getting 219 as the keycode for '['; however, the actual character value of '[' is 91. Is there any way to map these two?

3条回答
Evening l夕情丶
2楼-- · 2019-04-12 21:44

MapVirtualKey() is also useful.

查看更多
冷血范
3楼-- · 2019-04-12 21:45

step 1: Open VC++ 6.0
Step 2: File --> New --> Projects --> Win32 Application
Give your project name
Step 3: File --> New --> Files --> C++ Source File
Give your file name
step 4: In your CPP file

/* Mfc program to handle virtual key codes. */
#include<afxwin.h>
class myframe : public CFrameWnd
{
public: 
    myframe()
    {
        Create(0,"Menu Program");
    }
    void OnKeyDown(UINT n)
    {
        switch(n)
        {
        case VK_LEFT:
            MessageBox("Left Arrow","Hellow");
            break;
        case VK_RIGHT:
            MessageBox("Right Arrow","Hellow");
            break;
        case VK_UP:
            MessageBox("Up Arrow","Hellow");
            break;
        case VK_DOWN:
            MessageBox("Down Arrow","Hellow");
            break;
        case VK_NUMPAD0:
            MessageBox("Number ZERO","Hellow");
            break;
        case VK_NUMPAD9:
            MessageBox("Number NINE","Hellow");
            break;
        case VK_SPACE:
            MessageBox("Space Bar","Hellow");
            break;
        case VK_BACK:
            MessageBox("BACK KEY","Hellow");
            break;
        case VK_SHIFT:
            MessageBox("SHIFT KEY","Hellow");
            break;
        }
    }       
    DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myframe,CFrameWnd)
ON_WM_KEYDOWN()
END_MESSAGE_MAP()
class myapp : public CWinApp
{
public:
    int InitInstance()
    {
        m_pMainWnd=new myframe();
        m_pMainWnd->ShowWindow(3);      
        return 1;
    }
};
myapp app;

step 5: Project --> settings --> Choose MFC as shared DLL
Step 6: Bulid --> Compile
step 7: Build --> Build
Step 8: Build --> Execute

查看更多
贪生不怕死
4楼-- · 2019-04-12 22:00

If you are using Windows, you should look into the ToUnicodeEx function.

查看更多
登录 后发表回答