AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Function keys onFormKeyDown

Ein Thema von question · begonnen am 11. Sep 2013 · letzter Beitrag vom 11. Sep 2013
Antwort Antwort
question

Registriert seit: 17. Apr 2013
97 Beiträge
 
#1

Function keys onFormKeyDown

  Alt 11. Sep 2013, 11:48
Hi,
I would like to use the function key (F1) in my application. I was trying several times to make it work in the following way
Code:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
 if Key = VK_F1 then
    //do something here
it was not working then i fount that, if i make the "KeyPreview := True" then then it works
though i have read about it from several sites, neverthless i am not totally clear and therefore i need a suggestion, is that okay if i make "KeyPreview := True" or it can be affected
other event handlers? and should i need to make the Key := 0 at the end? like the follwoing way
Code:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
 if Key = VK_F1 then
    //do something here
Key := 0 // i mean here should i make it Key is zero
  Mit Zitat antworten Zitat
Der schöne Günther

Registriert seit: 6. Mär 2013
6.110 Beiträge
 
Delphi 10 Seattle Enterprise
 
#2

AW: Function keys onFormKeyDown

  Alt 11. Sep 2013, 11:58
I've never tried it myself, but this fine gentleman on SO reports that

Zitat:
The KeyPreview property of the current active form is checked for the KeyUp-, KeyDown- and KeyPress- event handlers of the current active control. I.e.: a key press in any control results in the check of the form's KeyPreview property.

If that property is True, the event handler in question invokes the event handler of the form prior to that of itself. If the form's event handler does not change the key value to 0 (or #0, depending on KeyPress or KeyDown/KeyUp), then the active control's event handler takes back over, otherwise the event is considered handled.
So it's pretty much like gestures work in Delphi: The Event in your form fires first, no matter which component is currently selected. If you assign Key := 0 in your TForm1.FormKeyDown , then the component that is currently selected won't even notice a key way pressed. If you want it do to some additional stuff, then don't zero it out

So KeyPreview itself does not affect other handlers, while setting Key to zero does.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:44 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz