Sign in Join
Wiki copytemporary

key down/de

Deutsch · English

Das Ereignis OnKeyDown eines Objektes erlaubt dem Programmierer festzustellen, welche Taste der Anwender gedrückt hat. Damit kann das Programm auf den Tastendruck des Anwenders gezielt reagieren.

Eine Taste abfragen

pascal
uses
  LCLType, Dialogs, ...;
  
  ...
  
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (Key = VK_DOWN) or
     (Key = VK_UP) then
    ShowMessage('Pfeiltaste gedrückt');
  Key := 0; // Notwendig, um in manchen Widgetsets wie Cocoa die Verarbeitung in weiteren UI-Elementen zu verhindern
end;

Zwei Tastencodes abfragen

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 definiert ist (z.B. ssAlt, ssCtrl, usw.).

pascal
uses
  LCLType, Dialogs, ...;
  
  ...
  
procedure TForm1.txtEditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
   if ssAlt in Shift then
    if Key = vk_F2 then
     ShowMessage('Alt F2 wurde gedrückt.')
   Key := 0; // Notwendig, um in manchen Widgetsets wie Cocoa die Verarbeitung in weiteren UI-Elementen zu verhindern
end;

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.

Revision 1, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.