Autor Beitrag
i-moro-de
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Do 01.10.09 15:22 
Hallo,

Ich habe ein kleines Programm geschrieben wo man ein Bild bewegen kann.
Ich würde es aber gerne so machen das man es über die Pfeiltasten steuern kann, und nicht über w, a, s oder d!
Ausserdem würde ich es gerne hinkriegen dass, wenn ich das bild an z.B. ein Panel dran bewege, es sich nicht in das panel reoinbewegt!

Hier mal der Quelltext:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if key='w' then Image1.top:=Image1.Top-10;{tastendruck w = nach oben!}
if key='s' then Image1.top:=Image1.Top+10;{tastendruck s = nach unten!}
if key='a' then Image1.left:=Image1.left-10;{tastendruck a = nach links!}
if key='d' then Image1.left:=Image1.left+10;{tastendruck d = nach rechts!}
end;


kennt jemand eine Lösung??

i-moro-de

Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt
Tryer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 226
Erhaltene Danke: 7



BeitragVerfasst: Do 01.10.09 15:59 
Lass Dir doch einfach anzeigen was beim Drücken der Pfeiltasten passiert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
 Caption := IntToStr(Ord(Key));
// if Ord(Key) = XX then YYY oder
// if Key = #XX then YYY oder
// case Ord(Key) of ..
end;


Grüsse, Dirk
i-moro-de Threadstarter
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Do 01.10.09 16:04 
und wie sehe ich das dann??

---Moderiert von user profile iconNarses: Beiträge zusammengefasst---

hab ich mal gemacht, aber wenn ich die Pfeiltasten drücke, ändert der den Titel nicht!
Tryer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 226
Erhaltene Danke: 7



BeitragVerfasst: Do 01.10.09 16:15 
Wodurch Du erkennst, das die Pfeiltasten im Gegensatz zu vielen anderen Tasten wohl nicht in "OnKeyPress" abgefragt werden können.
Dann versuch das ganze doch mal in OnKeyDown. Achung, da wird "Key" anders übergeben, nämlich direkt als "Ord" ;)
i-moro-de Threadstarter
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Do 01.10.09 16:19 
geht! Danke!
jetzt währe nur nich dass mit dem Hindernis!

moro
thepaine91
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 763
Erhaltene Danke: 27

Win XP, Windows 7, (Linux)
D6, D2010, C#, PHP, Java(Android), HTML/Js
BeitragVerfasst: Do 01.10.09 16:40 
Forensuche dazu gab es schon unzählige Threads.
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Do 01.10.09 16:45 
Hiondernis ist doch einfach nur ein Vergleichen der Position (Top und Left), bzw. der Höhe und Breite, zwischen dem Image und dem Panel.

_________________
PROGRAMMER: A device for converting coffee into software.
thepaine91
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 763
Erhaltene Danke: 27

Win XP, Windows 7, (Linux)
D6, D2010, C#, PHP, Java(Android), HTML/Js
BeitragVerfasst: Fr 02.10.09 09:25 
Hier da findest du mehr als genug ^^

Suche in der Entwickler-Ecke KOLLISION ABFRAGEN
i-moro-de Threadstarter
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Mi 07.10.09 13:19 
Ich hab ja schon sowas mit koordinatenangaben, aber gibt es auch eine einfachere methode??