Fabrizio
Fabrizio

Reputation: 8043

How are Ctrl + Key shortcuts translated in the OnKeyPress event?

I was trying to detect Ctrl+V from a TEdit's OnKeyPress event and I've noticed that the Key parameter assumes an unusual value when pressing Ctrl+AnyKey.

Example:

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  ShowMessage(IntToStr(Ord(Key)));
end;

It produces the following results:

I don't understand how keys are translated, what does these codes mean?

It seems it has nothing to do with the ASCII table:

enter image description here

Could anyone shed some light on this?

Upvotes: 3

Views: 3271

Answers (1)

LU RD
LU RD

Reputation: 34899

I don't understand how keys are translated, what does these codes mean?

The values you get with the Ctrl+AnyKey combinations are Ascii control codes. They emanate from the need to enter non-printing (control) characters from the keyboard. The (typical) values for the control characters are below 32 plus the del character (127).

enter image description here

Some more information about the history behind and standards could be found here and here.

Upvotes: 6

Related Questions