Autor Beitrag
Smile
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40

WinXP
D6 Pers
BeitragVerfasst: Do 03.07.03 16:37 
Ich habe eine Art SnakeClone programmiert bis jetzt mit Buttons um die Richtung zuändern. Nun wollte ich es mit den Cursortasten machen aber das gelingt mir net könnt ihr mir helfen? BITTE!

_________________
Smile or the day is lost! so -> :)
Tomac
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 113

Win XP
D6 Ent
BeitragVerfasst: Do 03.07.03 17:53 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
onkeydown...
case key of 
   vk_up: //schlange nach oben
   vk_down: //schlange nach unten
   vk_left: //schlange nach links
   vk_right: //schlange nach rechts
end;


meinst du das?

mfG
Tomac
Smile Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40

WinXP
D6 Pers
BeitragVerfasst: Do 03.07.03 20:32 
ja schon aber wo kommt dieser quelltext rein?
wann liest das Programm die tastatur aus?

ein einfaches Beispiel wäre net
z.b. etwas auf der form bewegen, ein X durch Cursor tasten bewegen wie geht das genau?

_________________
Smile or the day is lost! so -> :)
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Do 03.07.03 21:51 
Tomac hatte das ja schon geschrieben:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  case key of  
    vk_up: //schlange nach oben //irgendeineFunktion
    vk_down: //schlange nach unten 
    vk_left: //schlange nach links 
    vk_right: //schlange nach rechts 
  end;
end;


Hinter dem vk_up, etc. sind Doppelpunkte und du kannst mit begin und end; einen Anweisungsblock einschließen.

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
mquadrat
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 19


D6 Enterprise
BeitragVerfasst: Fr 04.07.03 09:19 
Falls etwas anderes als das Form gerade den Fokus haben sollt, musst du dann noch Form.KeyPreview auf true setzen. Wobei ich dafür keine Garantie übernehme bei mir funktionierts nämlich trotzdem nicht. Siehe auch mein Thread von gestern oder vorgestern..
Tomac
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 113

Win XP
D6 Ent
BeitragVerfasst: Fr 04.07.03 12:43 
@Smile:

Du hast ja die Bewegung bereits mit Hilfe von Buttons gemacht, ich gehe mal davon aus, dass du einen Button für rauf, runter... hast.
Wenn du dir nun Arbeit ersparen willst, mach die Buttons einfach unsichtbar und rufe die OnClick Ereignisse z.B. so auf:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; 
  Shift: TShiftState); 
begin 
  case key of   
    vk_up: button_rauf.click;
    vk_down: button_runter.click;
    vk_left: button_links.click; 
    vk_right: button_rechts.click; 
  end; 
end;


mfG
Tomac
Smile Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40

WinXP
D6 Pers
BeitragVerfasst: Fr 04.07.03 13:34 
danke

ich habe es mit buttons richtig habe auch diesen Quellcode drin
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; 
  Shift: TShiftState);  
begin  
  case key of    
    vk_up: button_rauf.click; 
    vk_down: button_runter.click; 
    vk_left: button_links.click;  
    vk_right: button_rechts.click;  
  end;  
end;

so aber es passiert nix! es ist doch eine Procedure aber muß man die nicht erst aufrufen? bis jetzt ändere ich nur die makierungen der buttons wenn ich die cursor drücke! :(

Moderiert von user profile iconTino: Code-Tags hinzugefügt.

_________________
Smile or the day is lost! so -> :)
Smile Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40

WinXP
D6 Pers
BeitragVerfasst: Fr 04.07.03 17:26 
ich habe hier mal ein komplettes "Programm" warum funktionieren die tasten nicht? :
ausblenden volle Höhe 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:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormKeyDown(Sender: TObject; var Key: word;Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormKeyDown(Sender: TObject; var Key: word;Shift: TShiftState);
begin
 case key of
  vk_escape: form1.Close;
  vk_space: form1.Close;
end;
end;

end.


Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.

_________________
Smile or the day is lost! so -> :)
Tweafis
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 647

WinXP + fbsd
Delphi 5 Prof
BeitragVerfasst: Fr 04.07.03 18:45 
Hast du die Funktion der Entsprechenden OnKeyDown der Form in der IDE im Objektinspektior zugewiesen???

_________________
.: Es wird der Tag kommen, an dem wir es nicht mehr ändern können :.
Smile Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40

WinXP
D6 Pers
BeitragVerfasst: Fr 04.07.03 20:03 
Tweafis hat folgendes geschrieben:
Hast du die Funktion der Entsprechenden OnKeyDown der Form in der IDE im Objektinspektior zugewiesen???


Bitte was?? :shock:
das ist alles wie es im Quellcode steht!
Wo kann ich das einstellen?

_________________
Smile or the day is lost! so -> :)
Tweafis
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 647

WinXP + fbsd
Delphi 5 Prof
BeitragVerfasst: Fr 04.07.03 20:07 
In der Entwicklungsumgebung wo du dein Formulargestaltest gehst du auf dein Form und wählst das an. Dann gehst du links in dem Fenster, dem Objektinspektor auf Ereignisse und doppelklickst auf OnKeyDown. In die erstellte proc muss dann der code rein.

_________________
.: Es wird der Tag kommen, an dem wir es nicht mehr ändern können :.
Smile Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40

WinXP
D6 Pers
BeitragVerfasst: Fr 04.07.03 20:50 
ok thx
das habe ich eingestellt trotzdem nix wenn ich die Cursor drücke ändert sich die markierung der buttons! :oops:

_________________
Smile or the day is lost! so -> :)
Tomac
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 113

Win XP
D6 Ent
BeitragVerfasst: Sa 05.07.03 16:05 
Komisch, bei mir funktioniert das einwandfrei. Hast du keypreview auf true?
Smile Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40

WinXP
D6 Pers
BeitragVerfasst: Sa 05.07.03 17:55 
ja habe ich aber muß ich da noch irgend ein Objekt einfügen?
was ist wenn du bei dir Buttons einfügst geht es dann immer noch?

_________________
Smile or the day is lost! so -> :)
StefanH
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1144

Win XP
D5 Standard, D7 Pers, D2005 Pers
BeitragVerfasst: Sa 05.07.03 20:07 
Smile hat folgendes geschrieben:
ich habe hier mal ein komplettes "Programm" warum funktionieren die tasten nicht? :


Wenn das dein ganzer Code ist, fehlen die Buttons und die Button-Prozeduren gibts auf net.

Stefan

_________________
"Als es noch keine Computer gab, war das Programmieren noch relativ einfach."(Edsger W. Dijkstra)
"Ich bin nicht von Sinnen, sondern ich rede wahre und vernünftige Worte." (Paulus)
Smile Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40

WinXP
D6 Pers
BeitragVerfasst: Sa 05.07.03 21:28 
was wil ich denn mit Buttons wenn es mit der Tastatur gesteuert werden soll? :shock:

_________________
Smile or the day is lost! so -> :)
Tomac
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 113

Win XP
D6 Ent
BeitragVerfasst: So 06.07.03 13:39 
Du rufst ja mit den Tasten die Buttonclick Ereignisse auf.
Probier vielleicht mal, den Code zum Bewegen der Schlange direkt in die Tastenabfrage zu schreiben.
smoo
Hält's aus hier
Beiträge: 6

Win 98

BeitragVerfasst: Sa 15.11.03 20:58 
das sieht ja alles ganz nett aus aber was ist wenn ich die steuerung auf
die WSAD Tsaten legen willl oder allgemein eine Buchstabentaste einbinden möchte ?

edit ....

ich habe da nen Thread gefunden das mir die antwort beitet aber nur wenn ich beispielsweise was auf die Taste a legen möchte muss ich vK_A schreiben aber jetzt meint delphi das Vk_A ein UNdefindierter Bezeichner wäre

aber was nun ?