Autor Beitrag
Jerk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Sa 29.12.07 13:36 
*edit* Lösung letzer Post von mir

Wenn ich eine Grafik mittels onKeyDown bewegen will und ich die bestimmte Taste gedrückt halte wartet Delphi immer kurz bevor die Bewegung einsetzt, wie kann ich das loswerden?

Wenn ich nur kurz drücke bewegt sich der Körper sofort.


Ich habe mal die Exe angehangen.
Einfach mal die Pfeiltaste links kurz drücken und dann mal gedrückt halten.
Beim gedrückthalten macht er erst einen Schritt, wartet dann kurz und bewegt sich dann halt bis man loslässt -.-

Wie kann ich es realisieren das wenn ich z.b. Pfeil-Links und Pfeil-Hoch drücke, das sich das ganze dann auch Diagonal nach oben links bewegt?
Das wenn ich links loslasse das er dann auch weiter nach oben geht?

Hier noch die Keydown procedure:
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_left : rotx:=rotx-0.1;
  vk_right : rotx:=rotx+0.1;
  vk_up : roty:=roty+0.1;
  vk_down :roty:=roty-0.1;
 end;
end;
*
Einloggen, um Attachments anzusehen!


Zuletzt bearbeitet von Jerk am Sa 29.12.07 15:21, insgesamt 2-mal bearbeitet
Bethsoftfan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 44

Win XP, Linux OpenSuSE 10.3 mit Compiz Fusion :cool:
Delphi 2007 Prof. Delphi 5
BeitragVerfasst: Sa 29.12.07 13:43 
Hallo,

einen Timer mit gewünschter Zeit und auf ereigniss OnTimer das gewünschte reinschreiben!

also bei KeyPressDown den Timer Enable true!
voher Timer enable auf false setzen!
Jerk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Sa 29.12.07 14:01 
Jo das mit dem Timer hat mich schonmal vorrangebracht, aber was ist mit dem Fall von zweu Pfeiltasten gleichzeigitg?

Wie sieht da die Variable key aus wenn ich zwei Tasten gleichzeitig drücke?

ich dachte an
ausblenden Delphi-Quelltext
1:
2:
3:
4:
case key of
  ...
  vk_left and vk_up : machwas;
end;


Geht aber nicht -.-


Zuletzt bearbeitet von Jerk am Sa 29.12.07 14:08, insgesamt 1-mal bearbeitet
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Sa 29.12.07 14:07 
Einfach im OnKeyDown eine Boolean-Variable auf true setzen und im OnKeyUp wieder auf false.
Dann einfach nur noch alle x ms diese Variable auf true prüfen und das Objekt entsprechend bewegen.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Bethsoftfan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 44

Win XP, Linux OpenSuSE 10.3 mit Compiz Fusion :cool:
Delphi 2007 Prof. Delphi 5
BeitragVerfasst: Sa 29.12.07 14:32 
Also dann:

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:
..
var
bol1 : boolean = true;
..


procedure Timer1.OnTimer
var
...
Begin
If bol1 = true Then
Begin
...
end;
end;

procedure Form1.KeyPressDown
Begin
case key of
...
vk_left and vk_up : bol1 := false;
end;

so oder?
Jerk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Sa 29.12.07 14:38 
Ich habe es so und es geht aus irgend einem Grund 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:
34:
35:
36:
37:
38:
39:
40:
41:
42:
var
  glokey  : array [1..2]of word;
  keyone  : boolean;
  keysafe : word;
...
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 if keyone=true then 
  begin
    glokey[1]:=key;
    glokey[2]:=keysafe;
  end
  else
  begin
   glokey[1]:=key;
   glokey[2]:=0;
  end;
 keyone:=true;
 keysafe:=key;
 timer1.enabled:=true;
end;
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
keyone:=false;
timer1.enabled:=false;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  case glokey[1] of
   vk_left : rotx:=rotx-0.1;
   vk_right : rotx:=rotx+0.1;
   vk_up : roty:=roty+0.1;
   vk_down :roty:=roty-0.1;
  end;
  case glokey[2] of
   vk_left : rotx:=rotx-0.1;
   vk_right : rotx:=rotx+0.1;
   vk_up : roty:=roty+0.1;
   vk_down :roty:=roty-0.1;
  end;
 end;
Bethsoftfan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 44

Win XP, Linux OpenSuSE 10.3 mit Compiz Fusion :cool:
Delphi 2007 Prof. Delphi 5
BeitragVerfasst: Sa 29.12.07 14:42 
Tja was für Fehlermeldungen ? (Glaskugel is inner Reparatur! ;) !

also der Timer muss natürlich wieder disable werden, und mach es lieber mit ner If .. Then ..Begin...end; abfrage!
Jerk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Sa 29.12.07 14:49 
habs grade selber rausgefunden, ne Fehlermeldung kommt nich aber Keypress ruft sich bei gedrückten Key andauernd auf, weshalb "Er" dachte das ich zwei tasten drücke obwohl es nur eine war...

Hmm wie mach ich das denn jetzt, Keypress ruft sich auch andauernd auf wenn ich gedrückt halte -.-


Zuletzt bearbeitet von Jerk am Sa 29.12.07 14:54, insgesamt 1-mal bearbeitet
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Sa 29.12.07 14:53 
Mit GetAsyncKeyState kriegst du immer raus, welche Taste gerade gedrückt ist, und welche nicht. Ein Timer mit if-Abfragen dieser Methode wäre meiner Meinung nach die schönere Lösung.
Jerk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Sa 29.12.07 14:59 
Wie Funktioniert die Function??
Bethsoftfan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 44

Win XP, Linux OpenSuSE 10.3 mit Compiz Fusion :cool:
Delphi 2007 Prof. Delphi 5
BeitragVerfasst: Sa 29.12.07 15:02 
Kinners ich hab gesagt nimmt meine Methode :mahn:

ok dann würde es so aussehen :
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:
34:
35:
36:
var  
  glokey  : array [1..2]of word;  
  keyone  : boolean;  
  keysafe : word;  
...  
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;  
  Shift: TShiftState);  
begin  
 case key of  
...  
 vk_left and vk_up : keyone := false;   
end;  
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);  
begin  
keyone:=false;    
end;  
procedure TForm1.Timer1Timer(Sender: TObject);  
begin 

  IF keyone = true THEN
  Begin 
  case glokey[1] of  
   vk_left : rotx:=rotx-0.1;  
   vk_right : rotx:=rotx+0.1;  
   vk_up : roty:=roty+0.1;  
   vk_down :roty:=roty-0.1;  
  end;  
  case glokey[2] of  
   vk_left : rotx:=rotx-0.1;  
   vk_right : rotx:=rotx+0.1;  
   vk_up : roty:=roty+0.1;  
   vk_down :roty:=roty-0.1;  
  end;
  timer1.enabled:=false;  
 end; 
end;


Wer Fehler findet, darf sie korrigieren! :P
DrRzf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 260

Win XP Prof
D7 Enterprise
BeitragVerfasst: Sa 29.12.07 15:08 
stelln sich ihm vermutlich schonmal 2 fragen. :nixweiss:
wo wird glokey[x] gesetzt ?
wo startest du den timer wieder ?

_________________
rein statistisch gesehen darf man keiner statistik trauen die man nicht selbst gefälscht hat.
Jerk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Sa 29.12.07 15:09 
Das Funktioniert nicht weil Keydown in die Variable immer nur einen Key reinschreibt also entweder VK_left oder VK_Up aber nicht beides!

Key ist word und nur word, d.h. kein array. Da passt nur eine zahl rein.
Das ist ja genau das Problem!


Zuletzt bearbeitet von Jerk am Sa 29.12.07 15:12, insgesamt 1-mal bearbeitet
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Sa 29.12.07 15:11 
Nimm doch einfach für jede Taste eine Variable... :roll:

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Jerk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Sa 29.12.07 15:14 
!!!
*HandgegenKopfklatsch*

Den einfachstenweg sieht man immer erst zum Schluss,
Danke!

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:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 case key of
 vk_left  : kleft :=true;
 vk_right : kright:=true;
 vk_up    : kup   :=true;
 vk_down  : kdown :=true;
 end;
 timer1.enabled:=true;
end;

procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
 case key of
 vk_left  : kleft :=false;
 vk_right : kright:=false;
 vk_up    : kup   :=false;
 vk_down  : kdown :=false;
 end;
 if (kleft  =false) and
    (kright =false) and
    (kup    =false) and
    (kdown  =false) then
     timer1.enabled:=false;
end;
procedure TForm1.Timer1Timer(Sender: TObject);  
begin
 if kleft  = true then rotx:=rotx-0.1;
 if kright = true then rotx:=rotx+0.1;
 if kup    = true then roty:=roty+0.1;
 if kdown  = true then roty:=roty-0.1;
end;


Funktioniert prima :)
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Sa 29.12.07 15:42 
Also, wenn ich mir den langen Quelltext ansehe, denke ich schon, wieso nicht einfach so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.TimerTimer(Sender: TObject);
begin
  if GetKeyState(VK_LEFT)  < 0 then rotx := rotx - 0.1;
  if GetKeyState(VK_RIGHT) < 0 then rotx := rotx + 0.1;
  if GetKeyState(VK_UP)    < 0 then rotx := roty + 0.1;
  if GetKeyState(VK_DOWN)  < 0 then rotx := roty - 0.1;
end;

Du fügst den Timer hinzu, setzt den Intervall, aktivierst ihn, und die beiden Variablen werden hoch- und runtergezählt. Ich denke mal, dass ein laufender Timer nicht so schlimm wäre, weil dein Programm offensitlich darauf basiert. Wenn es nur ein Dialogfeld ist, oder nur bei einer bestimten Komponente ausgeführt wird, kannst du ja den Timer entsprechend ein- und ausschalten.
Jerk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Sa 29.12.07 16:31 
Das is wieder ne Funktion die ich nicht kannte, das Programm basiert nicht auf dem Timer aber danke Dir !
Herr Bananerama
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 130



BeitragVerfasst: Sa 29.12.07 16:41 
Das problem bei einem Timer sollte doch auch sein das wenn man zweimal auf den Button klickt der Timer wieder ausgelöst wird. Ich würde also die Timer in einem Dynamischen Array erzeugen, oder ist das quatsch??^^
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Sa 29.12.07 16:46 
Ähem, entweder ich verstehe gerade einiges nicht, oder du hast etwas nicht verstanden. Es soll doch eine Tastatur-Taste abgefragt werden, nicht ein Button. Und ein Timer wird in einem bestimmten Intervall ausgelöst, nicht auf Knopfdruck. Er wird nur ein- und ausgeschaltet, aber wenn du zweimal auf einen An-Knopf drückst, ohne ihn vorher wieder auszuschalten, dann passiert auch nichts.
Bethsoftfan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 44

Win XP, Linux OpenSuSE 10.3 mit Compiz Fusion :cool:
Delphi 2007 Prof. Delphi 5
BeitragVerfasst: Sa 29.12.07 17:00 
entsteht dann nicht ein Laufzeitfehler, weil der Timer schon enable ist? :?!?: