Article View: borland.public.cppbuilder.nativeapi
Article #17404Re: Key Name to Virtual Key Code
From: Troels Jakobsen
Date: Wed, 26 Mar 2003 18:07
Date: Wed, 26 Mar 2003 18:07
40 lines
1935 bytes
1935 bytes
You can get the key name from the virtual code, but not the
other way round.
You can of course create a method that uses an array and
some mapping logic, but the easiest is to use brute force.
Say you have method VirtualKeyToKeyName that returns the
key name. You can then create a method, KeyNameToVirtualKey,
which calls VirtualKeyToKeyName until it returns a matching
key name:
string VirtualKeyToKeyName(int virtualKey) {
// return key name
}
int KeyNameToVirtualKey(string keyName) {
for (int i=0x08; i<0xFF; i++) {
if (AnsiCompareText(keyName, VirtualKeyToKeyName(i)) == 0) {
return i;
}
}
return -1;
}
This approach is a little CPU-intensive. On the positive side
it's simple, and it's independent of the user's language settings.
Troels
RaynorPao wrote in message <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.
Technical Details
Message-ID:
<3e81ec6c@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-09!supernews.com!iad-peer.news.verio.net!news.verio.net!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<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 20:56:02 PST From: "Troels Jakobsen" <dont@like.spam> Newsgroups: borland.public.cppbuilder.nativeapi References: <3e8158e9@newsgroups.borland.com> Subject: Re: Key Name to Virtual Key Code Date: Wed, 26 Mar 2003 19:07:56 +0100 Lines: 42 X-Newsreader: Microsoft Outlook Express 4.72.2106.4 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 NNTP-Posting-Host: 80.196.79.114 Message-ID: <3e81ec6c@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1048702060 80.196.79.114 (26 Mar 2003 10:07:40 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-09!supernews.com!iad-peer.news.verio.net!news.verio.net!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail