[delphi] Wykrywanie naciskania przycisków w joyu

0

Jak wykryć naciśniecie przycisku powiedzmy 1 na joyu?

0

DirectX/DelphiX -> TDXInput

0

mógłby ktoś napisać jak użyć tego komponentu, żeby sprawdzić który przycisk jest wcisnięty?

0

To szantaż? Tu masz kod, bez DirectX, samo MMSystem.

uses MMSystem;

TForm1 = class (TForm);
  //...
  procedure FormCreate(Sender: TObject);
  procedure Joy1Move(var msg:TMessage); message MM_JOY1MOVE;
  end;

var
   Form1: TForm1;
   JoyCnt:Byte;    
   JoyAct:Boolean; 
   JoyCps:JoyCaps; 
   Joy_Pos:JoyInfoEx;

procedure TForm1.FormCreate(Sender: TObject);
begin
Joy_Pos.dwSize:=sizeof(Joy_Pos);
Joy_Pos.dwFlags:=JOY_RETURNAll;
JoyCnt:=JoyGetNumDevs();
JoyAct:=(joyGetPosEX(JOYSTICKID1,@Joy_Pos)<>JOYERR_UNPLUGGED);
if (JoyAct) then
   begin
   JoyGetDevCaps(JOYSTICKID1,@JoyCps,sizeof(joycaps));
   ComboBox.Items.Insert(0,JoyCps.szPname);
   end;
ComboBox.Enabled:=JoyAct and not (JoyCnt=0);
//Wybranie joysticka
JoySetCapture(Handle, ComboBox.ItemIndex, 50, false);
end;

procedure TForm1.Joy1Move(var msg:TMessage);
begin
joyGetPosEX(JOYSTICKID1,@Joy_Pos);
RadioButton1.Checked:=(Joy_Pos.wButtons and 1)=1;
RadioButton2.Checked:=(Joy_Pos.wButtons and 2)=2;
RadioButton3.Checked:=(Joy_Pos.wButtons and 4)=4;
RadioButton4.Checked:=(Joy_Pos.wButtons and 8)=8;
RadioButton5.Checked:=(Joy_Pos.wButtons and 16)=16;
RadioButton6.Checked:=(Joy_Pos.wButtons and 32)=32;
RadioButton7.Checked:=(Joy_Pos.wButtons and 64)=64;
Xpos.Text:=inttostr(Joy_Pos.wXpos);
Ypos.Text:=inttostr(Joy_Pos.wYpos);
Zpos.Text:=inttostr(Joy_Pos.wZpos);
Rpos.Text:=inttostr(Joy_Pos.dwRpos);
case Joy_Pos.dwPOV of
   0:PovN.Checked:=true;
   4500:PovEN.Checked:=true;
   9000:PovE.Checked:=true;
   13500:PovES.Checked:=true;
   18000:PovS.Checked:=true;
   22500:PovWS.Checked:=true;
   27000:PovW.Checked:=true;
   31500:PovWN.Checked:=true;
   else PovCenter.Checked:=true;
   end;
end;

Kiedyś napisałem prosty programik to testowania ruchu joysticka - to jego kluczowy fragment. Jak chcesz go w całości, odezwij się na GG.

1 użytkowników online, w tym zalogowanych: 0, gości: 1