🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #17387

Re: Key Name to Virtual Key Code

#17387
From: Rodolfo Frino - Stargate Softwar...
Date: Wed, 26 Mar 2003 12:13
72 lines
2971 bytes
There is no API to do that, that I'm aware of.
You can do it like that or you can use a map,
something like this (untested) code

#include <map>
std::map<String, unsigned int> VirtualKeyMap;

unsigned int VirtualKey_NameToCode(String VKName)
{
    return VirtualKeyMap[VKName];
}

void Set_VirtualKeyMap()
{
    VirtualKeyMap["VK_LBUTTON" ] = 0x01;
    VirtualKeyMap["VK_RBUTTON"  ] =  0x02;
    VirtualKeyMap["VK_CANCEL"   ] =   0x03;
    VirtualKeyMap["VK_MBUTTON" ]  = 0x04;
    VirtualKeyMap["VK_XBUTTON1" ] = 0x05;
    VirtualKeyMap["VK_XBUTTON2"]  =  0x06;
    //VirtualKeyMap["" ] =  07;
    VirtualKeyMap["VK_BACK" ] = 0x08;
    VirtualKeyMap["VK_TAB" ] = 0x09;
    //VirtualKeyMap["" ] =   0A;
    //VirtualKeyMap["" ]  =   0B;
    VirtualKeyMap["VK_CLEAR"    ]  =  0x0C;
    VirtualKeyMap["VK_RETURN"   ] = 0x0D;
    //VirtualKeyMap["" ] =  0E;
    //VirtualKeyMap["" ] =  0F;
    VirtualKeyMap["VK_SHIFT"    ] = 0x10;
    VirtualKeyMap["VK_CONTROL"  ] = 0x11;
    VirtualKeyMap["VK_MENU"     ] = 0x12;
    VirtualKeyMap["VK_PAUSE"    ] = 0x13;
    VirtualKeyMap["VK_CAPITAL"  ] = 0x14;
    VirtualKeyMap["VK_KANA"     ] = 0x15;
    VirtualKeyMap["VK_HANGUEL"  ] = 0x15;
    VirtualKeyMap["VK_HANGUL"   ] = 0x15;
    //VirtualKeyMap["" ] =  16;
    //All the rest
}
//---------------------------------------------------------------------

__fastcall   TForm1 :: TForm1(TComponent* Owner)
        : TForm(Owner)
 {
    Set_VirtualKeyMap();
 }

void __fastcall TForm1:: Button1Click(TObject *Sender)
{
    ShowMessage(String(VirtualKey_NameToCode("VK_RETURN")));
    ShowMessage(String(VirtualKey_NameToCode("VK_SHIFT")));
}

Rodolfo

"RaynorPao" <RaynorPao.nospam@nospam.pchome.com.tw> wrote in message
news:3e8158e9@newsgroups.borland.com...
> Hi all:
>
> Is there an API can convert Key Name to Virtual Key Code?
> For example:
>
> char sz[16]="F1";
> int i=KeyNameToVirtualKeyCode(sz);
>
> The value of i will be VK_F1.
>
> Thanks.
> RaynorPao.
>
>
Technical Details
Message-ID: <3e81a26b@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3e8158e9@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,59cf09bcf2259d6d
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-03-26 04:56:22 PST
From: "Rodolfo Frino - Stargate Software" <starcinema@eftel.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3e8158e9@newsgroups.borland.com>
Subject: Re: Key Name to Virtual Key Code
Date: Wed, 26 Mar 2003 23:13:53 +1100
Lines: 74
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
NNTP-Posting-Host: 203.129.132.66
Message-ID: <3e81a26b@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1048683115 203.129.132.66 (26 Mar 2003 04:51:55 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail