• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5139
  • Last Modified:

Convert (var Key: Word) to ASCII Character

FormKeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);

There has to be an easy way to  convert (Key) to the ASCII equivalent?
Something like;
    s: String;
    s := WordToStr(Key);

Brain Dead........

Greg Rowland
Greg Rowland
6 Solutions
Eddie ShipmanAll-around developerCommented:
Char(Key), perhaps?
Eddie ShipmanAll-around developerCommented:
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
  if ssShift in Shift then

Chr(Key) will give a char (see also ord() function)

Char will cast the word, I will not recommend.

you could use it like that

if (chr(Key)='a') or (chr(key)='A') then
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Geert GOracle dbaCommented:
this is a virtual key you are getting
check the VK_ constants in the windows unit

ciuly created a small unit to create such a unit once for me:

that time it was for the messages.
Geert GOracle dbaCommented:
>> Never did get any of this to meet my needs, please close question.

you haven't even posted a remark

this is not just ask a question and wait for an answer
if you see you aren't getting anywhere then post some more info
or react on the comments
Eddie ShipmanAll-around developerCommented:
I agree, you were given several correct answers to your question on how to convert the word in a KeyDown to a character.

You must select one or more as the answer, dude!
Eddie ShipmanAll-around developerCommented:
modus, why did you select an answer?
Greg RowlandSoftware Designer, SysDBA, WebMaster OwnerAuthor Commented:
I selected an answer as I  could not bear the complaints.
Eddie ShipmanAll-around developerCommented:
It would have been easier to tell us what about the posted solutions didn't work for you than to try to delete the question without an explanation. As I said earlier, you were given several correct answers to your question and you were expected to select one or more.

If you'd been more upfront with us, there would have not been any complaints.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now