目前 的 MMSYSTEM 的
joytokey
可以获得 飞行摇杆的 两个方向 及 油门 
却无法 获得 方向舵的哪位朋友知道啊

解决方案 »

  1.   

    Wxpos  WYpos WzPos wRPos
      

  2.   

    DirectInput
    开发包在http://www.delphi-jedi.org下载var
    guidInstance: TGUID;
    function DIEnumDevicesCallbackW(var lpddi: TDIDeviceInstanceW; pvRef: Pointer): BOOL; stdcall;
    var
     tmpDInput    :IDirectInput8W;
     tmpDInputJoy :IDirectInputDevice8W;
    begin
     result:=False;
     if Failed(DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8W, tmpDInput, nil)) then exit;
     result:=Succeeded(tmpDInput.CreateDevice(lpddi.guidInstance, tmpDInputJoy, nil));
     guidInstance:=lpddi.guidInstance;
     tmpDInputJoy:=nil;
     tmpDInput:=nil;
    end;function DirectInputJoy(lpDInput :IDirectInput8W; h_wnd :THandle; out lpDInputJoy :IDirectInputDevice8W) :HRESULT;
    var
    DIPropRange:TDIPropRange;
    DIPropDWord:TDIPropDWord;
    begin
    Result:= E_FAIL;
    if Failed(lpDInput.EnumDevices(DI8DEVTYPE_JOYSTICK,DIEnumDevicesCallbackW,nil,DIEDFL_ATTACHEDONLY)) then exit;
    if Failed(lpDInput.CreateDevice(guidInstance, lpDInputJoy, nil)) then exit;
    if Failed(lpDInputJoy.SetCooperativeLevel(h_wnd, DISCL_NONEXCLUSIVE or DISCL_FOREGROUND)) then exit;
    //手柄范围
    DIPropRange.diph.dwSize := sizeof(TDIPropRange);
    DIPropRange.diph.dwHeaderSize := sizeof(TDIPropHeader);
    DIPropRange.diph.dwHow  := DIPH_DEVICE;
    DIPropRange.diph.dwObj  := 0;
    DIPropRange.lMax        := 100;
    DIPropRange.lMin        := -100;
    if Failed(lpDInputJoy.SetProperty(DIPROP_RANGE,DIPropRange.diph)) then exit;
    //中心死区
    DIPropDWord.diph.dwSize :=sizeof(TDIPropDWord);
    DIPropDWord.diph.dwHeaderSize:=sizeof(TDIPropHeader);
    DIPropDWord.diph.dwHow  :=DIPH_DEVICE;
    DIPropDWord.diph.dwObj  :=0;
    DIPropDWord.dwData      :=1000;
    if Failed(lpDInputJoy.SetProperty(DIPROP_RANGE,DIPropRange.diph)) then exit;
    if Failed(lpDInputJoy.SetDataFormat(c_dfDIJoystick2)) then exit;
    result:=S_OK;
    end;//使用
    var
    DInput       :IDirectInput8W;      //DirectInput对象
    DInputJoy    :IDirectInputDevice8W;//手柄输入
    JoyState       :TDIJoyState2;
    begin
    //建立DirectInput
    if not (DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8W, DInput, nil)=DD_OK) then exit;
    DirectInputJoy(DInput, MainHandle, DInputJoy);
    //处理手柄事件
     if not (DInputJoy=nil) then begin
       if not (DInputJoy.GetDeviceState(sizeof(TDIJoyState2),@JoyState)=DD_OK) then
         DInputJoy.Acquire;
    //对应上下左右
    //   JoyState.lX
    //   JoyState.lX
    //   JoyState.lY
    //   JoyState.lY
     end;
    //释放
    if not (DInputJoy=nil) then
      try     DInputJoy.Unacquire;
      finally DInputJoy   :=nil;
      end;
    DInput      :=nil;
    end;
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls, StdCtrls, ComCtrls, Series, TeeProcs, mmsystem, Buttons,
      Grids, DBGrids, DB, ADODB, TeeFunci, DbChart, Chart;type
      TMMJoyStick  = packed record
        Msg:     Cardinal;  // The message ID
        Buttons: Longint;   // The wParam
        Pos1:    word;      // The lParam
        Pos2:    word;
        Pos3:    word;
        Pos4:    word;
        Result:  Longint;
    end;type
      TForm1 = class(TForm)
        Label1: TLabel;
        Panel1: TPanel;
        Label2: TLabel;
        CBB1: TPDJXPComboBox;
        Label10: TLabel;
        PDJXPProgressBar3: TPDJXPProgressBar;
        Label11: TLabel;
        PDJXPProgressBar4: TPDJXPProgressBar;
        Label12: TLabel;
        ......
        ADOConnection1: TADOConnection;
        ADOQuery1: TADOQuery;
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
    procedure Joy1Move(var msg:TMessage); message MM_JOY1MOVE;
      end;var
      Form1: TForm1;
       JoyCnt:Byte;
       JoyAct:Boolean;
       JoyCps:JoyCaps;
       Joy_Pos:JoyInfoEx;  C2_1, C2_2, C2_3, C2_4 : Boolean;implementation{$R *.dfm}procedure TForm1.Joy1Move(var msg:TMessage);
    begin
    joyGetPosEX(JOYSTICKID1,@Joy_Pos);
    CheckBox1.Checked:=(Joy_Pos.wButtons and 1)=1;
    CheckBox2.Checked:=(Joy_Pos.wButtons and 2)=2;
    CheckBox3.Checked:=(Joy_Pos.wButtons and 4)=4;
    CheckBox4.Checked:=(Joy_Pos.wButtons and 8)=8;  PDJXPProgressBar1.position := Joy_Pos.wXpos;
      PDJXPProgressBar2.position := Joy_Pos.wYpos;
      PDJXPProgressBar3.position := Joy_Pos.dwRpos;
      PDJXPProgressBar4.position := Joy_Pos.wZpos;end;procedure TForm1.FormCreate(Sender: TObject);
    var JoyMsg : Integer;
    begin  C2_1 := False;
      C2_2 := False;
      C2_3 := False;
      C2_4 := False;//捕获游戏操纵杆             // Thisis19780606Hlq
    JoyMsg := joySetCapture(Handle,JOYSTICKID1,0,false);
    Application.Title := '太阳能检测系统';
    if (JoyMsg = JOYERR_NOCANDO)then begin
        ShowMessage('   不能捕获接口板!    ');Halt;end else
    if(JoyMsg=JOYERR_UNPLUGGED) Then begin
    ShowMessage('   接口板未与系统连接!   ');Halt;end else
    if(JoyMsg =MMSYSERR_NODRIVER) then begin
    ShowMessage('   系统没有安装接口板!   ');Halt;end else begin
    ShowMessage('       接口板连接成功!        ');
    {
      if RasConnectionCount=0 then  begin
    ShowMessage('无法进行身份识别!');Halt;end else
      end;}
    ADOConnection1.ConnectionString :=
    'Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source='+
     ExtractFilePath(Application .ExeName)+ 'Cx.dbf';
     ADOQuery1.Connection := ADOConnection1;
     DataSource1.DataSet := ADOQuery1;
    DBChart1.Series[0].DataSource := ADOQuery1;
    DBChart1.Series[0].XValues.ValueSource := '时间';
    DBChart1.Series[0].YValues.ValueSource := 'C1_3';
    DBChart1.Series[0].XValues.DateTime := True;
    DBChart1.Series[1].DataSource := ADOQuery1;
    DBChart1.Series[1].XValues.ValueSource := '时间';
    DBChart1.Series[1].YValues.ValueSource := 'C2_1';
    DBChart1.Series[1].XValues.DateTime := True;
    DBChart1.Series[2].DataSource := ADOQuery1;
    DBChart1.Series[2].XValues.ValueSource := '时间';
    DBChart1.Series[2].YValues.ValueSource := 'C1_1';
    DBChart1.Series[2].XValues.DateTime := True;
    //---------------------------------------------
    PDJXPProgressBar1.max:=64000;
    PDJXPProgressBar2.max:=64000;
    PDJXPProgressBar3.max:=64000;
    PDJXPProgressBar4.max:=64000;
    //---------------------------------------------
    Joy_Pos.dwSize:=sizeof(Joy_Pos);
    Joy_Pos.dwFlags:=JOY_RETURNAll;
    JoyCnt:=JoyGetNumDevs();
    JoyAct:=(joyGetPosEX(JOYSTICKID1,@Joy_Pos)<>JOYERR_UNPLUGGED);
    if (JoyAct) then
       JoyGetDevCaps(JOYSTICKID1,@JoyCps,sizeof(joycaps));//Wybranie joysticka
    JoySetCapture(Handle, joystickid1, 100, false);
      end;end;end.
      

  4.   

    抱歉
    yufei
    我无法加分,而且也不能结贴