How to convert virtual key code to character code?

In the handler, onkeydown()I get 219as a key code for '['; however, the actual meaning of the character '[' is equal 91. Is there a way to match these two?

+3
source share
3 answers

If you use Windows, you should study the ToUnicodeEx function .

+3
source

step 1: Open VC ++ 6.0
Step 2: File → Create → Projects → Win32 Application
      Specify the name of the project
Step 3: File → Create → Files → C ++ source file
      Specify the 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;

5: → → MFC DLL
6: Bulid →
7: →
8: →

+1

MapVirtualKey () is also useful.

0
source

Source: https://habr.com/ru/post/1733835/


All Articles