![]() |
Keypress Problem bei Setfocus
Hallo
Delphi-Quellcode:
Es funktioniert nur wenn der Focus in einem Edit !
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState); begin if(Key =39)then begin ShowMessage('Pfeil rechts'); end; Wenn ein BitBtn Button zum beispiel den Focus hat, dann funktioniert nicht |
Re: Keypress Problem bei Setfocus
Im OI für die Form KeyPreview auf True setzen.
|
Re: Keypress Problem bei Setfocus
Zitat:
|
Re: Keypress Problem bei Setfocus
Hallo,
zum sicheren Abfangen der Pfeiltasten könnte man das Ereignis TForm.OnShortCut verwenden:
Delphi-Quellcode:
Gruß Hawkeye
procedure TForm1.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
var Key : TShortCut; begin Key := {Menus.}ShortCut(Msg.CharCode, KeyDataToShiftState(Msg.KeyData)); if (Key = VK_RIGHT) then begin ShowMessage ('Gotcha!'); Handled := True; end |
Re: Keypress Problem bei Setfocus
Zitat:
Teste doch ______ Zitat:
Edit : Es gibt aber ein problem mit der Tasten kombination zum beispiel :
Delphi-Quellcode:
Danke :thumb:
if ((Key = VK_CONTROL) and (Key = VK_RIGHT) ) then
begin ShowMessage ('CTRL + Pfeil'); // Reagiert nicht ! Handled := True; end |
Re: Keypress Problem bei Setfocus
Hallo Thomas,
ich sehe deine Ergänzung leider erst jetzt. Natürlich kannst du auch Kombinationen mit den Umschalttasten abfragen:
Delphi-Quellcode:
Gruß Hawkeye
procedure TForm1.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
var Key : TShortCut; begin Key := {Menus.}ShortCut(Msg.CharCode, KeyDataToShiftState(Msg.KeyData)); if (Key = scShift or VK_RIGHT) then begin ShowMessage ('Gotcha!'); Handled := True; end; end; |
Re: Keypress Problem bei Setfocus
Key Taste die zwölfte (oder waren es schon mehr) von thomas2009 ? :wink:
|
Re: Keypress Problem bei Setfocus
Ich verstehe nicht, warum mit "or" funktioniert aber mit "and" nicht !
Delphi-Quellcode:
...
if (Key = scShift or VK_RIGHT) then |
Re: Keypress Problem bei Setfocus
die Pfeiltasten müssen über die entsprechende Message erlaubt werden wm_getdlgkey oder wo ähnlich.
|
Re: Keypress Problem bei Setfocus
Moin Thomas,
in dem Beispiel sieht es so aus:
Code:
Wenn jetzt diese Tasten gleichzeitig gedrückt werden, ist
scShift = 8192 = 10000000000000 (bin)
VK_RIGHT = 39 = 100111 (bin)
Code:
da jetzt
Key = 8231 = 10000000100111 (bin)
Code:
ist (bei logischer Und-Verknüpfung werden alle Bits 1, die bei beiden Werten 1 sind, ansonsten wird's 0)
scShift and VK_RIGHT = 0
und
Code:
ist (bei logischer Oder-Verknüpfung werden alle Bits 0, die bei beiden Werten 0 sind, ansonsten wird's 1),
scShift or VK_RIGHT = 10000000100111
ist die Gleichheit nur bei OR gegeben. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:07 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz