Autor Beitrag
TimonWorld
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 397



BeitragVerfasst: So 25.04.04 14:19 
Hi! Ich will ein Programm programmieren dass auch mit einem Gamepad gesteuert werden kann! Problem: Wie kann man auslesen welche Gemepad-Taste gedrückt wurden ist!!!
Adrian
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 314



BeitragVerfasst: Mo 26.04.04 07:30 
Servus!

Mir fallen da vorerst 2 Möglichkeiten ein:
- Die JEDI-JVCL-Komponenten bieten mit "JvMultimedia /JvJoystick" die nötige Unterstützung.
- Bei DelphiX wird der Joystick (bzw. das Gamepad) mit DXInput abgefragt.
Solltest Du mit Win95/98/Me arbeiten, dann gibt es da noch weitere, relativ hardwarenahe Möglichkeiten, bei Bedarf kann ich Dir hierfür einen Pascal-Code geben.

Gruß,

Adrian
TimonWorld Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 397



BeitragVerfasst: Mo 26.04.04 17:38 
Adrian hat folgendes geschrieben:
kann ich Dir hierfür einen Pascal-Code geben.


THX - Wäre echt voll nett von dir!
Adrian
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 314



BeitragVerfasst: Di 27.04.04 07:02 
Servus!

Hier der versprochene Pascal-Code:
ausblenden volle Höhe 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:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
program joy;
{ Gibt an, welche Tasten an einem Joystick gedrückt sind, und auf welcher
  Position der Kreuzknüppel steht. }

uses crt,
     dos;

function joyx : word;
begin
  inline($1E/$50/$52/$56/$BA/$01/$02/$B4/$01/$BE/$00/$00/$8E/$DE/$FA
  /$EE/$46/$EC/$84/$C4/$75/$FA/$FB/$89/$36/$64/$12/$5E/$5A/$58/$1F);
  joyx:=memw[0:$1264];
end;

function joyy : word;
begin
  inline($1E/$50/$52/$56/$BA/$01/$02/$B4/$02/$BE/$00/$00/$8E/$DE/$FA
  /$EE/$46/$EC/$84/$C4/$75/$FA/$FB/$89/$36/$64/$12/$5E/$5A/$58/$1F);
  joyy:=memw[0:$1264];
end;

function button1 : boolean;
begin
  button1:=(port[$201] and 16)=0;
end;

function button2 : boolean;
begin
  button2:=(port[$201] and 32)=0;
end;

procedure aus;
{ Schaltet Cursor aus }
var r : registers;
begin
  r.ah:=1;
  r.ch:=$20;
  r.cl:=1;
  intr($10,r);
end;

procedure ein;
{ Schaltet Cursor ein }
var r : registers;
begin
  r.ah:=1;
  r.ch:=11;
  r.cl:=12;
  intr($10,r);
end;

{ ********************* }
{ *** HAUPTPROGRAMM *** }
{ ********************* }
begin
  aus;
  clrscr;
  repeat
    if button1 then
    begin
      gotoxy(1,1);
      write('Knopf 1 ist gedrückt       ');
    end
    else
    begin
      gotoxy(1,1);
      write('Knopf 1 ist nicht gedrückt ');
    end;
    if button2 then
    begin
      gotoxy(1,2);
      write('Knopf 2 ist gedrückt       ');
    end
    else
    begin
      gotoxy(1,2);
      write('Knopf 2 ist nicht gedrückt ');
    end;
    gotoxy(1,3);
    delay(250);
    write('X-Wert: ',joyx,'     ');
    gotoxy(1,4);
    delay(250);
    write('Y-Wert: ',joyy,'     ');
  until keypressed;
  ein;
end.

Die beiden Funktionen joyx und joyy stammen nicht von mir, die fand ich vor ca. 8 Jahren in irgendeiner Zeitschrift. Ein damaliger Arbeitskollege - ein Elektroingenieur, der zuvor aber auch was Anständiges gelernt hat :wink: - konnte sie auch halbwegs verstehen. Mir war die Funktionsweise nicht so wichtig, Hauptsache war, daß es funktioniert. Unter DOS, Win3.11 und Win95 war dem auch so, bei anderen Betriebssystemen habe ich es nie ausprobiert - aber das kannst Du ja jetzt machen.

Gruß,

Adrian