Difference between revisions of "OnKeyPress"
From Free Pascal wiki
Jump to navigationJump to searchJwdietrich (talk | contribs) (Creating this article) |
m (Fixed syntax highlighting; removed categories included in template) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
== Overview == | == Overview == | ||
+ | |||
The {{Doc|package=LCL|unit=controls|identifier=twincontrol.onkeypress|text= OnKeyPress}} event of an object allows you to check what key the user has pressed. | The {{Doc|package=LCL|unit=controls|identifier=twincontrol.onkeypress|text= OnKeyPress}} event of an object allows you to check what key the user has pressed. | ||
Line 9: | Line 10: | ||
== Example == | == Example == | ||
− | <syntaxhighlight> | + | |
+ | <syntaxhighlight lang=pascal> | ||
uses | uses | ||
...LCLType, Dialogs, ...; | ...LCLType, Dialogs, ...; | ||
Line 27: | Line 29: | ||
== See also == | == See also == | ||
+ | |||
* [[LCL Key Handling]] Detailed background on key handling in the LCL. | * [[LCL Key Handling]] Detailed background on key handling in the LCL. | ||
− | + | * [[key down]] | |
− | [[ |
Latest revision as of 05:33, 23 February 2020
Overview
The OnKeyPress event of an object allows you to check what key the user has pressed.
Note that this procedure handles printable characters only. Non-printable characters (e.g. control sequences) are handled by the OnKeyDown event.
Note: OnKeyPress doesn't support Unicode characters. If you need Unicode characters but no control characters, use OnUTF8KeyPress.
Example
uses
...LCLType, Dialogs, ...;
...
procedure TMainForm.FormKeyPress(Sender: TObject; var Key: char);
begin
case key of
'0': ShowMessage('"0" key pressed');
'1': ShowMessage('"1" key pressed');
'2': ShowMessage('"2" key pressed');
end;
Key := #0; // Necessary for some widgetsets, e.g. Cocoa, in order to disable processing in subsequent elements.
end;
See also
- LCL Key Handling Detailed background on key handling in the LCL.
- key down