Autor Beitrag
Aceman
Hält's aus hier
Beiträge: 13



BeitragVerfasst: So 06.03.05 17:13 
Kann mir jemand sagen wie das mit dem ereignis OnKeyPress geht.
Ich will jetzt z.B. das wenn ich die "enter" taste drücke dass
dann die die label1.Caption auf z.B. aktiviert unspringt

Also irgendwas mit Labe1.Caption ('Akriviert')
Aber wo stelle ich ein welche taste gedrückt werden soll usw.

Brauche Hilfe!! :?:


Moderiert von user profile iconKlabautermann: Topic aus Multimedia / Spiele / Grafik verschoben am Di 20.09.2005 um 21:58
wdbee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 628
Erhaltene Danke: 1



BeitragVerfasst: So 06.03.05 17:50 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  case Key of
   'X': DoXAction;
   'Y': DoYAction;
   'Z': DoZAction;
  else
    DoDefaultAction;
  end;
end;
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: So 06.03.05 17:51 
Im OnKeyPress Event wird die Variable Key mit übergeben. In der wird gespeichert welche taste gedrückt wurde.
Ergo:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
 if key=#13 then label1.Caption := 'aktiviert';  // #13 = Enter.  // bspw. 'a' würde auch gehen.
end;
Aceman Threadstarter
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Mo 07.03.05 19:34 
Wo kann ich den nachgucken welche Zahl welche taste ist??
spaxxn
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 31

WinXP SP3, Win2000 SP4, Debian Sarge
D7 EE, D2006 PE, D2007 EE
BeitragVerfasst: Di 08.03.05 12:14 
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: Di 20.09.05 20:09 
Es geht bei mir einfach nicht.. Ich hab es mit allen möglichkeiten Probiert

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
 if key=#49 then Button1.Caption := 'test';
 end;

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);   
begin   
  case Key of   
   '1': Button1.Caption:='TEST';   
  end;   
end;


Es geht einfach nicht :'( :'( :'(
Irgendwelche Ideen? :D

greetz

Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 20.09.05 20:11 
Benutze OnKeyDown, statt OnKeyPress.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: Di 20.09.05 20:19 
Es geht, nur das ist nicht ganz was ich meine :(
Das problem ist, das ich es in meinen Taschenrechner einfügen will, und dieser mehrere Panels hat. Ich glaube es würde gehen, wenn der taschenrechner überhaupt keine panels hätte, aber das ist ja nicht was ich möchte.

Also noch mal zum verständnis: Man soll z.B. 1 drücken können, egal "wo" man gerade beim Taschenrechner ist (z.B. gerade auf Panel1, Panel2, oder Edit1)

Ich habe es natürlich versucht mit Form1, aber das geht ja leider nicht :(:(:(

greetz
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: Di 20.09.05 20:35 
Hallo,

@GTA-Place: genau!

Dazu ein Auszug aus der Delphi-Hilfe:
Zitat:
Da der Parameter Key den Datentyp Char hat, registriert das Ereignis OnKeyPress das ASCII-Zeichen der gedrückten Taste. Tasten, die keinem ASCII-Char-Wert entsprechen (z.B. UMSCHALT oder F1), generieren kein Ereignis OnKeyPress. Tastenkombinationen (z.B. UMSCHALT+A) führen nur zu einem Ereignis OnKeyPress (in diesem Beispiel ergibt UMSCHALT+A den Key-Wert „A“, wenn die Feststelltaste deaktiviert ist). Soll auf Nicht-ASCII-Tasten oder Tastenkombinationen reagiert werden, verwenden Sie die Ereignisbehandlungsroutine für OnKeyDown oder OnKeyUp.


@Born-to-Frag: setz KeyPreview der Form auf True.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: Di 20.09.05 20:48 
OK, thx Lannes, das hat jetzt geholfen!!
Aber jetzt noch ne blöde Frage, wo ich aber keinen neuen Threat anfangen brauch:
Wie kann ich KeyPreview der Form1 standardmäßig auf True setzten, damit ich OnKeyPress nutzen kann :)?

greetz
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: Di 20.09.05 20:55 
Habs schoon gelöst :D