Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
Get the name of a keyboard key Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
06-Feb-03
Category
Win API
Language
Delphi 2.x
Views
108
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Lou Adler 

Does anyone know how to get the name of a key from the keyboard? I want a method 
that sends the ASCII code and returns the correct name in string format.

Answer:

Start with calling VkKeyScan, then proceed to GetKeynameText, via MapVirtualKey.

1   function GetKeyname(ch: Char): string;
2   var
3     scan: Word;
4     virtual_keycode: Byte;
5     keyname: array[0..128] of Char;
6     lparam: Integer;
7   begin
8     scan := VkKeyScan(ch);
9     Result := '';
10    if scan <> $FFFF then
11    begin
12      if (Scan and $100) <> 0 then
13        Result := Result + '[Shift]';
14      if (Scan and $200) <> 0 then
15        Result := Result + '[Ctrl]';
16      if (Scan and $400) <> 0 then
17        Result := Result + '[Alt]';
18      virtual_keycode := Lobyte(scan);
19      lparam := MapVirtualKey(virtual_keycode, 0) shl 16;
20      if lparam <> 0 then
21        if GetKeyNametext(lparam, keyname, sizeof(keyname)) > 0 then
22          Result := Result + '[' + keyname + ']';
23    end;
24  end;
25  
26  procedure TForm1.Button1Click(Sender: TObject);
27  begin
28    memo1.text := GetKeyname(alignededit1.text[1]);
29  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC