Autor Beitrag
benicz
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

Win XP
Turbo Delphi 2006
BeitragVerfasst: Mi 23.05.07 14:31 
hallo!

alsi hui für mein programm nutze ich u.a. die tastatur.
als ja/nein-tasten habe ich da logischerweise ok und esc gewählt.
bis jetzt habe ich damit immer unterfenster geschlossen,
ds hauptfenster hat nur was bei esc machen sollen.
jetzt soll es auch beim enter-drücken was machen, und siehe da:

klapptnich!

selbst wenn ich direkt zu beginn von onkeydown einen haltepunkt setze,
bleibt er bei ziemlich allen tasten stehen, aber nicht bei enter!

how come?!

PS:
keypreview ist an
uwewo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 154



BeitragVerfasst: Mi 23.05.07 14:35 
Zeig mal etwas Code, damit uns das RATEN einfacher fällt.
benicz Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

Win XP
Turbo Delphi 2006
BeitragVerfasst: Mi 23.05.07 14:40 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
procedure TFMain.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key in [48..57then
    begin
      kombsel.execute(key-48);
      exit;
    end;
  case key of
    13:
      if kombsel.enabled then
        kombsel.execute($FF);
    27:
      begin
        if kombsel.enabled then
          kombsel.execute($FE);
        if learn.enabled then
          postmessage(self.Handle, WM_Schaltexit, 0,0);
        if bearb.enabled then
          bearb.execute(_EEnde, 0,0,0);
      end;
    end;
end;
Stefan.Buchholtz
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 612

WIN 2000, WIN XP, Mac OS X
D7 Enterprise, XCode, Eclipse, Ruby On Rails
BeitragVerfasst: Mi 23.05.07 14:49 
Der Parameter Key in FormKeyDown enthält nicht den ASCII-Code der Taste, sondern den virtuellen Tastencode.

Du kannst entweder statt OnKeyDown das OnKeyPress-Event verwenden, mit dem du den ASCII-Code übergeben bekommst, oder in deinem case-Statement auf die virtuellen Keycodes prüfen. Die sind als Konstanten definiert, Enter- und Escape-Tasten sind VK_RETURN und VK_ESCAPE.
So müsste es funktionieren:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
procedure TFMain.FormKeyDown(Sender: TObject; var Key: Word;  
  Shift: TShiftState);  
begin  
  if key in [48..57then  
    begin  
      kombsel.execute(key-48);  
      exit;  
    end;  
  case key of  
    VK_RETURN:  
      if kombsel.enabled then  
        kombsel.execute($FF);  
    VK_ESCAPE:  
      begin  
        if kombsel.enabled then  
          kombsel.execute($FE);  
        if learn.enabled then  
          postmessage(self.Handle, WM_Schaltexit, 0,0);  
        if bearb.enabled then  
          bearb.execute(_EEnde, 0,0,0);  
      end;  
    end;  
end;


Stefan

_________________
Ein Computer ohne Windows ist wie eine Schokoladentorte ohne Senf.
benicz Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

Win XP
Turbo Delphi 2006
BeitragVerfasst: Mi 23.05.07 14:59 
danke erstmal,
aber das kann leider nicht die lösung sein, weil
1. die VK_..'s ja nur konstanten sind

und vor allem
2. er ja gar nicht so weit kommt...
es sieht so aus, als würde keydown gar nicht aufgerufen!

habe schon überlegt, ob die enter-taste für mainforms gesperrt ist, aber das macht irgendwie keinen sinn...

noch ne idee?
uwewo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 154



BeitragVerfasst: Mi 23.05.07 15:04 
Im OI

ausblenden Delphi-Quelltext
1:
KeyPreview := True					


???
benicz Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

Win XP
Turbo Delphi 2006
BeitragVerfasst: Mi 23.05.07 15:11 
ist gesetzt, hatte ich anfangs geschrieben...

wie gesagt, ich weiß langsam nicht mehr weiter :-(
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 23.05.07 15:23 
Hallo,

wenn z.B. ein Button den Focus hat bekommt die Form VK_RETURN nicht mit, denn die Message wird von Windows direkt an den Button geschickt. Unter anderem beim Button-Focus auch VK_TAB, VK_Down ...

Man muss entweder den Focus auf eine andere Komponente setzen oder Windows zuvor kommen und die Message CM_DIALOGKEY abfangen.

:arrow:
VK_TAB geht nicht (fast) alle anderen schon

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
benicz Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

Win XP
Turbo Delphi 2006
BeitragVerfasst: Mi 23.05.07 15:34 
ok, es klappt, wenn ich ein steuerelement fokussiere, das kein button ist.
aber genau dafür ist doch keypreview da, oder nicht?

in allen anderen forms funktioniert es doch einwandfrei, und auch da sind buttons vorhanden.
war das zufall?
da muss doch ein unterschied sein...
uwewo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 154



BeitragVerfasst: Mi 23.05.07 15:45 
Nimm doch einen Button der keinen Focus besitzt, ich glaube TBitButton ist so einer.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 23.05.07 15:53 
Hallo,
user profile iconbenicz hat folgendes geschrieben:
ok, es klappt, wenn ich ein steuerelement fokussiere, das kein button ist.
aber genau dafür ist doch keypreview da, oder nicht?
ja aber nur die Tasten die nicht für die Steuerung/Navigation der jeweiligen Komponente zuständig sind
In der Delphi-Hilfe unter KeyPreview findest Du auch noch eine Erklärung.

user profile iconbenicz hat folgendes geschrieben:
in allen anderen forms funktioniert es doch einwandfrei, und auch da sind buttons vorhanden.
war das zufall?
da muss doch ein unterschied sein...
ja, das war Zufall. Setz doch mal auf der Form, bei der es nach Deiner Meinung nicht so ist, einen Button und gib diesem den Focus. Immer noch Zufall :wink:

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
benicz Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

Win XP
Turbo Delphi 2006
BeitragVerfasst: Mi 23.05.07 16:19 
ok, hab jetzt ne mischung aus keydown für zahlen und nachricht für ok/esc.
ich hoffe da komm ich mit klar und finde noch workarounds für die anderen elemente (edit's und so)...

danke aber für die schnelle hilfe!