Autor Beitrag
flaavia
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 105

WinXp Vista
D6 Ent, D2007 Ent
BeitragVerfasst: So 03.08.03 21:03 
Hallo

Ich versuche einige Buttons mit einem Joypad anzusteuern, so daß alle Datenabfragen (die sich im Prinzip mit 4 Buttons steuern lassen) über den (wireless) Joypad steuern lassen. Leider scheint die Integration eines Joypad schwieriger zu sein, als ich zunächst dachte.
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 Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, MMSystem, DB, ADODB, Grids, DBGrids, Menus, MPlayer, ExtCtrls,
  DBCtrls, jpeg, ComCtrls, Buttons;

//...

private
    { Private declarations }
      AMMResult : MMResult;
//...

implementation


{$R *.dfm}

procedure TfoMain.FormActivate(Sender: TObject);
begin
 begin
  AMMResult := JoySetCapture(Self.Handle, JOYSTICKID1, 0, True);
  if AMMResult <> 0 then 
     ShowMessage('Kann Joystick nicht überwachen')
   else
      ShowMessage('Kann Joystick überwachen');
  end;

// ... + andere bei FormActivate durchzuführende Einstellungen
end;

Beim ersten Aktivieren der foMain scheint es soweit zu funktionieren, wenn ich dann aus foMain eine andere Form aufrufe und von dieser zurück komme, erhält AMMResult den Wert 166 :?: - leider kann ich damit nichts anfangen.

Dies passiert weiter, obwohl ich den Sourcecode erweitert habe um:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TfoMain.FormDeactivate(Sender: TObject);
begin
  joyReleaseCapture(JOYSTICKID1);
end;

Auch scheint diese Art des Aufrufs nur unter FormActivate zu funktionieren, unter FormCreate habe ich jedenfalls eine ganze Latte an Fehlermeldungen erhalten.

Und zu guter letzt verstehe ich nicht, wie ich den Buttons des Joypads die Funktionen zuweisen kann, die sonst über normale mausanklickbare Buttons ausgelöst werden. :?: :?:

Über alle Tips werde ich mich sehr freuen, wobei mir am meisten das Problem kopfzerbrechen macht, wie ich überhaupt die Joypad Buttons den Delphi-Funktionen zuordnen kann :nixweiss:

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: So 03.08.03 21:12 
Hi,

wieso willst du auch den Joypad bei jedem OnActivate neu überwachen??? einmal im FormCreate reicht vollkommen aus und sollte problemlos funktionieren ;)

Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: So 03.08.03 21:15 
Hi nochmal,

hab deine frage nach den Buttons übersehen :oops:

Wenn du einen Button am Joypad drückst, wird an Windows eine Message geschickt: MM_JOY1BUTTONDOWN bzw MM_JOY1BUTTONUP

Diese mußt du abfangen. anhand des wParam kannst du dann rausbekommen welcher Button gedrückt wurde :)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
    if (JOY_BUTTON1 and wParam) <> 0 then Button1Pressed;
    if (JOY_BUTTON2 and wParam) <> 0 then Button2Pressed;
    if (JOY_BUTTON3 and wParam) <> 0 then Button3Pressed;
    if (JOY_BUTTON4 and wParam) <> 0 then Button4Pressed;


Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
flaavia Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 105

WinXp Vista
D6 Ent, D2007 Ent
BeitragVerfasst: So 03.08.03 22:07 
Vielen Dank

Sollte sich der Quelltext wie unter FormActivate auch einfach in FormCreate einbauen lassen :?:

Als ich das zuerst versucht habe, kam unter anderem die Fehlermelung:
Zitat:
AMMResult undeclared identifier

und auch weiter bei
ausblenden Delphi-Quelltext
1:
AMMResult := JoySetCapture(Self.Handle, JOYSTICKID1, 0, True);					

konnte delphi mit Self.Handle nichts anfangen. Muß ich den Code hier anders gestalten, wenn ich JoySetCapture in OnFormCreate starte :?:

Edit:
Habe den Code jetzt nochmal in OnFormCreate gepackt - und es funktioniert - Keine Ahnung warum es anfangs nicht funktioniert hatte - ist aber jetzt auch egal :oops: Die Frage die noch bleibt - poste ich gleich neu weil ich unter der edit funktion keinen Zugriff auf Deine Antwort habe

Moderiert von user profile iconTino: Quote- & Delphi-Tags hinzugefügt.
flaavia Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 105

WinXp Vista
D6 Ent, D2007 Ent
BeitragVerfasst: So 03.08.03 22:54 
Hallo Aya


Wie genau kann ich die MM_JOY1BUTTONDOWN bzw MM_JOY1BUTTONUP abfragen, dh in welche procedure muß ich was schreiben, um diese Ereignisse abzufragen. Das Joypad hat 12 Knöpfe und ich wollte u.a. auch einen Knopf mit der Nr 8 abfragen (weil er günstiger liegt). Kann ich die von Dir genannten Abfragen dann einfach erweitern mit
ausblenden Delphi-Quelltext
1:
if (JOY_BUTTON8 and wParam) <> 0 then Button8Pressed;					

oder ist bei Buttons mit Nr > 4 ein anderes vorgehen notwendig?

Moderiert von user profile iconTino: Delphi-Tags hinzugefügt.
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: So 03.08.03 23:12 
Hi,

mit dem MMSystem kannst du nur maximal 4 Buttons abfragen, da bin ich damals auch dran gescheitert.. ;)

Wenn du mehr haben möchtest bleibt die wohl oder übel erstmal nurnoch DirectInput (von DirectX). Ist ziemlich einfach damit :)

Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
flaavia Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 105

WinXp Vista
D6 Ent, D2007 Ent
BeitragVerfasst: So 03.08.03 23:27 
Hallo Aya und alle, die sich für diese Diskussion interessieren

Ich habe mal folgendes versucht:
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:
25:
//...
public
    { Public declarations }
     procedure DefaultHandler(var Msg); override;
//...

procedure TfoMain.DefaultHandler(var Msg);
  var 
        Button1Pressed: Boolean;
        Button2Pressed: Boolean;
        Button3Pressed: Boolean;
        Button4Pressed: Boolean;
begin
  inherited DefaultHandler(Msg);

  case TMessage(Msg).Msg of
   MM_JOY1BUTTONDOWN, MM_JOY1BUTTONUP:
         begin
           if (JOY_BUTTON1 and wParam) <> 0 then Button1Pressed;
           if (JOY_BUTTON2 and wParam) <> 0 then Button2Pressed;
           if (JOY_BUTTON3 and wParam) <> 0 then Button3Pressed;
           if (JOY_BUTTON4 and wParam) <> 0 then Button4Pressed;
         end;
  end;
end;


Dies führt zu folgender Fehlermeldung
Zitat:
[Error] Main.pas(346): '(' expected but ')' found // hinter wParam
[Error] Main.pas(346): Statement expected, but expression of type 'Boolean' found

irgend etwas fehlt wohl noch hinter wParam: wParam( :?: ) und welches statement wird denn noch erwartet?

Oder ist der ganze Ansatz falsch :?: muss in der Public declaration
ausblenden Delphi-Quelltext
1:
2:
3:
public
    { Public declarations }
     procedure DefaultHandler(var Msg); override;

overide stehen oder nicht (oder führt ein ganz anderer Ansatz zum Ziel :?: :?: )

Moderiert von user profile iconTino: Delphi- & Quote-Tags hinzugefügt.
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: So 03.08.03 23:34 
Hi,

du hast 3 möglichkeiten ;)

1. du überschreibst die WndProc
2. du erstellst für deinen Joypad nen eigenes HWND an das die Messages geschickt werden
3. du machst es so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
  public
    procedure WMButton1Down(var Message: TMsg); message MM_JOY1BUTTONDOWN;

[...]

procedure TForm1.WMButton1Down(var Message: TMsg);
begin
  //Hier deinen abfrage code
end;


und diesen Teil:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
  case TMessage(Msg).Msg of 
   MM_JOY1BUTTONDOWN, MM_JOY1BUTTONUP: 
         begin 
           if (JOY_BUTTON1 and wParam) <> 0 then Button1Pressed; 
           if (JOY_BUTTON2 and wParam) <> 0 then Button2Pressed; 
           if (JOY_BUTTON3 and wParam) <> 0 then Button3Pressed; 
           if (JOY_BUTTON4 and wParam) <> 0 then Button4Pressed; 
         end
  end;


solltest du so machen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
  case TMessage(Msg).Msg of 
   MM_JOY1BUTTONDOWN, MM_JOY1BUTTONUP: 
         begin 
           Button1Pressed:=(JOY_BUTTON1 and wParam) <> 0;
          //Das gleiche für Button 2..4
         end
  end;


Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
flaavia Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 105

WinXp Vista
D6 Ent, D2007 Ent
BeitragVerfasst: Mo 04.08.03 00:20 
:idea:

Vielen herzlichen Dank

Werde ich gleich morgen ausprobieren :!:

Mit freundlichen Grüssen

Flaavia
flaavia Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 105

WinXp Vista
D6 Ent, D2007 Ent
BeitragVerfasst: Fr 08.08.03 08:52 
Hallo Aya

Nochmals vielen Dank

Zitat:
und diesen Teil:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
  case TMessage(Msg).Msg of  
   MM_JOY1BUTTONDOWN, MM_JOY1BUTTONUP:  
         begin  
           if (JOY_BUTTON1 and wParam) <> 0 then Button1Pressed;  
           if (JOY_BUTTON2 and wParam) <> 0 then Button2Pressed;  
           if (JOY_BUTTON3 and wParam) <> 0 then Button3Pressed;  
           if (JOY_BUTTON4 and wParam) <> 0 then Button4Pressed;  
         end;  
  end;

solltest du so machen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
  case TMessage(Msg).Msg of  
   MM_JOY1BUTTONDOWN, MM_JOY1BUTTONUP:  
         begin  
           Button1Pressed:=(JOY_BUTTON1 and wParam) <> 0
          //Das gleiche für Button 2..4 
         end;  
  end;

bei:
ausblenden Delphi-Quelltext
1:
Button1Pressed:=(JOY_BUTTON1 and wParam) <> 0;					

bekomme ich weiterhin die Fehlermeldung mit Cursor hinter wParam)
Zitat:
[Error] Main.pas(373): '(' expected but ')' found

hast Du eine Idee, wo hier der Fehler liegt bzw. was Delphi an weiterer Eingabe hinter wParam erwartet

Vielen Dank

Moderiert von user profile iconTino: Quote- & Delphi-Tags hinzugefügt.
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Fr 08.08.03 15:20 
Hi,

die zeile muß so aussehen:
ausblenden Delphi-Quelltext
1:
Button1Pressed:=(JOY_BUTTON1 and Message.wParam) <> 0;					


Also Message.wParam, nicht einfach nur wParam :)

Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!