Autor Beitrag
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: So 05.10.03 12:15 
Hallo,
ich möchte das die maus meiner anwendung immer in der MITTE ist, aber wie geht das ?

_________________
MFG
Michael Springwald, "kann kein englisch...."
Raphael O.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1596


VS 2013
BeitragVerfasst: So 05.10.03 12:25 
ich poste dir einfach mal den Wuelltext aus meinem Programm dafür...
du kannst duie Maus nicht immer ganz genau in der Mitte festhalten, kansnt aber einen Bereich einschränken, in den sie hineindarf ;)
alelrdings musst du beachten, das man das Programm dann nicht mehr mit der Maus beenden kann (alternativ: ALt+F4)...
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:
23:
24:
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: integer);
var
  NeueMausPos: TPoint;
begin
  NeueMausPos := Mouse.CursorPos;
  if altemauspos.X < neuemauspos.X then
    yrot := yrot - Abs(altemauspos.X - neuemauspos.X) ;
  if altemauspos.X > neuemauspos.X then
    yrot := yrot + Abs(altemauspos.X - neuemauspos.X);
  if (altemauspos.Y > neuemauspos.Y) {and (xrot>-60)} then
    xrot := xrot - Abs(altemauspos.Y - neuemauspos.Y) ;
  if (altemauspos.Y < neuemauspos.Y) {and (xrot<60) } then
    xrot := xrot + Abs(altemauspos.Y - neuemauspos.Y);
  altemauspos := neuemauspos;
  if neuemauspos.X < (Left + 10then SetCursorPos(Left + ClientWidth - 11, neuemauspos.Y);
  if neuemauspos.X >= (Left + ClientWidth - 10then
    SetCursorPos(Left + 11, neuemauspos.Y);
  if neuemauspos.Y < (Top + 80then SetCursorPos(neuemauspos.X, Top + ClientHeight - 11);
  if neuemauspos.Y >= (Top + ClientHeight - 10then
    SetCursorPos(neuemauspos.X, Top + 81);
  neuemauspos := Mouse.CursorPos;
  altemauspos := neuemauspos;
end;

btw: hier siehst du auch gleich, wei ich den yrot-Wert verändere...
die Maus ist bei meinem Quelltext nicht näher als 10px am Rand, aber die Entfernung kannst du ja leicht variieren...

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


Zuletzt bearbeitet von Raphael O. am Mo 10.11.03 18:42, insgesamt 1-mal bearbeitet
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: So 05.10.03 12:31 
also den haufen quelltext kannste dir auch sparen. das geht so viel einfacher:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.FormCreate(Sender: TObject);
var
  Rec: TRect;
begin
  Rec.Left := Left;
  Rec.Top := Top;
  Rec.Right := Left + Width;
  Rec.Bottom := Top + Height;
  ClipCursor(@Rec);
end;

Um den alten Mausbereich wiederherzustellen genügt:
ausblenden Delphi-Quelltext
1:
ClipCursor(nil);					

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Raphael O.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1596


VS 2013
BeitragVerfasst: So 05.10.03 12:35 
:lol:
na gut, ich gebe mich gelschlagen *g*
aber nicht umsonst steht in meiner Signatur:
Zitat:
Warum einfach, wenns auch kompliziert geht???

:mrgreen:
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: So 05.10.03 12:38 
ne so habe ich mir das nicht vorgestellt :(
ich wollte gerne das die MAUS IMMER in der mitte ist und dann auch nicht mehr weg kann.

_________________
MFG
Michael Springwald, "kann kein englisch...."
Raphael O.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1596


VS 2013
BeitragVerfasst: So 05.10.03 12:44 
wofür brauchst du das denn??
außerdem:
stell doch einfach das Rect so ein, das die Maus nur 1 Pixel in der Mitte des Bildschirms hat...
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 05.10.03 12:45 
Und was hindert dich daran den Code von matze zu nehmen? Der macht genau das,was du willst, die Maus einsperren.
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: So 05.10.03 12:45 
währe eine lösung.
ich brauche es für ein spiel. was ich mit GLScene mache

@Luckie
ich will die maus nicht einspren, das nützt mir nichts, ich will das sich die maus pos ändern und zwar sich ständig in der mittte aufhält und nirgendswo andres

_________________
MFG
Michael Springwald, "kann kein englisch...."
Raphael O.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1596


VS 2013
BeitragVerfasst: So 05.10.03 12:50 
hab ichs mir doch gedacht ;)
allerdings ist es dafür doch unsinnig, die Maus immer auf einem Pixel in der Mitte fetzuhalten...
selbst bei z.B. CS ist das nciht der Fall :D
als Fadenkreuz solltest du die Maus allerdings auf KEINEN Fall benutzen...
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: So 05.10.03 12:56 
gut, ich will einfach nu verhinder das die maus erstes das forum verläst und zweitens soll die maus immer an der gleichen pos stehen.

und warum soll ich die maus nicht als Fadenkreuz verwenden ?

_________________
MFG
Michael Springwald, "kann kein englisch...."
Terra23
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 872

Win 8
Delphi 7
BeitragVerfasst: So 05.10.03 14:09 
Du könntest doch die Bildschirmbreite und -höhe auslesen und dann dividieren und die Mausposition festlegen:

So definieren:

ausblenden Delphi-Quelltext
1:
2:
3:
Var
 AngLeft: Integer;
 AngTop: Integer;


So festlegen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.FormCreate(Sender: TObject);
begin
AngLeft:=Screen.Width DIV 2;
AngTop:=Screen.Height DIV 2;
end;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Timer1OnTimer(Sender: TObject);
begin
SetCursorPos(AngLeft, AngTop);
end;


Wenn ich nichts vergessen habe, müßte das so funktionieren. Probier's mal aus und teile mir mal mit, wo ggf. die Fehler liegen..

_________________
Hasta La Victoria Siempre
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: So 05.10.03 14:49 
leider ist die maus noch nicht ganz in der mitte, aber vom prinzip her funktoniert es danke.

_________________
MFG
Michael Springwald, "kann kein englisch...."
Terra23
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 872

Win 8
Delphi 7
BeitragVerfasst: So 05.10.03 16:09 
... kein Problem. Man hilft, wo man kann..

_________________
Hasta La Victoria Siempre
Raphael O.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1596


VS 2013
BeitragVerfasst: So 05.10.03 18:21 
das die Maus nicht ganz in der Mitte ist liegt wahrscheinlich an der Taskleiste :/

du solltest die Maus nicht als Fadenkreuz verwenden, weil man die Position nicht 100% fixieren kann und der Cursor außerdem sehr unflexibel ist...
->deshalb zeichne dir selber in die Mitte des Bildschirms ein Fadenkreuz, blende die Maus auch...
dann kannst du auch z.B. die Form und größe des Fadenkreuz immer verändern...
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: So 05.10.03 19:05 
das ist wohl die einfachste möglichkeit.
mal sehen, ich wollte ja erstmal nur das die maus an einer festen position es, weil das ganze soll in ein paar jahren mal ein 3D Ego shooter der ersten klasse werden *G*

_________________
MFG
Michael Springwald, "kann kein englisch...."
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 05.10.03 19:59 
In ein paar Jahren? Wenn du soweit bist gibt es keine Win32API mehr.
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: So 05.10.03 20:55 
meinst du ?
kann ich mir nicht vorstellen, naja ein paar jahren war viliecht übertrieben *G*

_________________
MFG
Michael Springwald, "kann kein englisch...."
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 05.10.03 23:59 
Stimmt, Jahrzehnte dürfte eher hinkommen.
simplex3
Hält's aus hier
Beiträge: 14

Win 98, Win 2000, Linux
D7.1 Prof, D8 Prof
BeitragVerfasst: Mi 16.02.05 16:52 
matze hat folgendes geschrieben:
also den haufen quelltext kannste dir auch sparen. das geht so viel einfacher:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.FormCreate(Sender: TObject);
var
  Rec: TRect;
begin
  Rec.Left := Left;
  Rec.Top := Top;
  Rec.Right := Left + Width;
  Rec.Bottom := Top + Height;
  ClipCursor(@Rec);
end;

Um den alten Mausbereich wiederherzustellen genügt:
ausblenden Delphi-Quelltext
1:
ClipCursor(nil);					


Also bei mir klappt das nicht. Die Maus kann ohne Probleme aus dem Form heraus bewegt werden..

_________________
Ceterum censeo, microsoftem esse delendam.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mi 16.02.05 18:38 
Probier's hiermit:

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:
// (...)

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    FRect : TRect;
    procedure ActivateApp(Sender : TObject);
    procedure DeactivateApp(Sender : TObject);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
 Application.OnActivate := ActivateApp;
 Application.OnDeactivate := DeactivateApp;
 FRect := Rect(Screen.Width div 2, Screen.Height div 2,
               Screen.Width div 2, Screen.Height div 2);
end;

procedure TForm1.ActivateApp(Sender: TObject);
begin
 ClipCursor(@FRect);
end;

procedure TForm1.DeactivateApp(Sender: TObject);
begin
 ClipCursor(nil);
end;

// (...)