Sign in Join
Wiki copytemporary

key down/de: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: key down/de

OldNewLine
1+Das Ereignis [OnKeyDown](https://lazarus-ccr.sourceforge.io/docs/lcl/controls/twincontrol.onkeydown.html) eines Objektes erlaubt dem Programmierer festzustellen, welche Taste der Anwender gedrückt hat. Damit kann das Programm auf den Tastendruck des Anwenders gezielt reagieren.
2+
3+## Eine Taste abfragen
4+
5+``` pascal
6+uses
7+ LCLType, Dialogs, ...;
8+
9+ ...
10+
11+procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
12+ Shift: TShiftState);
13+begin
14+ if (Key = VK_DOWN) or
15+ (Key = VK_UP) then
16+ ShowMessage('Pfeiltaste gedrückt');
17+ Key := 0; // Notwendig, um in manchen Widgetsets wie Cocoa die Verarbeitung in weiteren UI-Elementen zu verhindern
18+end;
19+```
20+
21+## Zwei Tastencodes abfragen
22+
23+Einmal wird die Tastaturcode in der Variablen *Key* und einmal wird der Tastaturcode in der Variablen *Shift* abgefragt. Die Variable Shift übergibt nur den Tastaturcode der in der Aufzählung [TShiftState](https://www.freepascal.org/docs-html/rtl/classes/tshiftstate.html) definiert ist (z.B. ssAlt, ssCtrl, usw.).
24+
25+``` pascal
26+uses
27+ LCLType, Dialogs, ...;
28+
29+ ...
30+
31+procedure TForm1.txtEditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
32+begin
33+ if ssAlt in Shift then
34+ if Key = vk_F2 then
35+ ShowMessage('Alt F2 wurde gedrückt.')
36+ Key := 0; // Notwendig, um in manchen Widgetsets wie Cocoa die Verarbeitung in weiteren UI-Elementen zu verhindern
37+end;
38+```
39+
40+---
41+*From the Free Pascal wiki, page "key down/de", as it stood on 2020-02-18 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history