Autor Beitrag
JaketheSnake
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 149

XP
D5 Prof.
BeitragVerfasst: Di 08.11.05 21:01 
Ich programmier grad ein spiel und im Hinergrund hab ich ein image. Jatzt will ich , dass wenn ich auf den linken maus button klicke eine bistimmt aktion ausgeführt wird. Geht auch eigendlich einwandfrei, doch sobald ich mit dem Cursor auf dem image bin passiert gar nichts .

Beispiel :
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
begin
     if button = mbleft then
      showmessage (' blabla ');
end;


Was mache ich falsch ?


Moderiert von user profile iconGausi: Topic aus Sonstiges verschoben am Di 08.11.2005 um 21:04

_________________
Good, better , best
Harry M.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754

Win 2000, XP
D2005
BeitragVerfasst: Di 08.11.05 21:15 
Form1.Key????? := True; Ich glaube Keypreview. Grad kein Delphi am start zum nachsehen.

_________________
Gruß Harry
Et spes me per dies sine te ducat et amor me ferat, si dolor spem tollit.
JaketheSnake Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 149

XP
D5 Prof.
BeitragVerfasst: Di 08.11.05 21:22 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
      if button = mbleft then
      showmessage (' blabla ');
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
     if button = mbleft then
      showmessage (' blabla ');
end;

procedure TForm1.FormKeypreview(Sender: TObject; var Key: Char);
begin
     if button = mbleft then
      showmessage (' blabla ');
end;

end.


Hab die drei Formen ausprobiert keine Funktioniert.

Keypreview kennt er net.

_________________
Good, better , best
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 08.11.05 21:25 
KeyPrewiev ist nur für Tastatur-Ereignisse, nicht für Mausklicks. Mir fällt im Moment nur die Lösung ein, Das Form1.OnClick auch in Image1.Onclick einzutragen. Aber für elegant halte ich die Lösung nicht...

_________________
We are, we were and will not be.
JaketheSnake Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 149

XP
D5 Prof.
BeitragVerfasst: Di 08.11.05 21:37 
Keine schlechte idee, doch es geht ja um FormMouseDown und auf das kann man schlecht klicken ...

...oder hab ich das Falsch verstanden ?

_________________
Good, better , best
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: Di 08.11.05 21:39 
Mir fällt auch nix elegantes ein...nur ein manuelles überprüfen ob die Maustaste (links ist 1) gedrückt wurde...

Ich poste mal meinen Code, kannste ja solang benutzen, bis jemand das richtige postet...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure aThread();
begin
 while true do
  if boolean(getAsyncKeyState(1)) then
   if form1.active then
    form1.clickaufform();
end;


Der Thread überprüft durchgängig ob die linke Maustaste gedrückt wurde.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
function active():boolean;
var P : TPoint;
begin
 getCursorPos(P);
 active := ((p.x > form1.Left) and (p.x < form1.left+form1.Width)
     and (p.Y > form1.top) and (p.Y < form1.Top+form1.Height));
end;


Die Funktion überprüft ob der Klick auch auf der Form passiert ist, und nicht irgendwo auffem Desktop.



In die Prozedur ClickAufForm kannst du dann das eintragen was du gemacht haben möchtest (also z.B. dein Showmessage).

Den Thread im OnCreate aufrufen mit Suche in: Delphi-Forum, Delphi-Library CREATETHREAD

KeyPreview war übrigens auch mein erster Gedanke...JaketheSnake, KeyPreview ist auch eine Property und kein Event.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 08.11.05 21:41 
Ähm, ich meinte auch MouseDown.

Das Problem ist ja, wenn du auf dem image den Mausbutton drückst, dann erhält das Image die Nachricht MouseDown, nicht die Form.

Daher muss man entwede dafür sorgen, dass Image1.OnMouseDown das selbe macht wie Form1.OnMousedown, oder eben, dass die nachricht an die Form weitergeleitet wird.

Einfacher dürfte für dan Anfang aber sein, wenn du bei Image1.OnmouseDown die Form1.OnMouseDown-Prozedur einträgst. Musst nur aufpassen, wenn du die Koordianten benutzt - die musst du dann ggf. umrechnen.

_________________
We are, we were and will not be.