这个所谓映射说白了关键就是要懂得怎样操作手柄,懂得操作手柄就行了。你需要下载DirectX的SDK,不然就用第三方组件提供的包装好的DX相关功能。
第三方组件中比较简单易用的是老牌的DelphiX,安装好后,用它DXINPU控件就能操作手柄了,看它目录中的demo,简简单单几句
unitMain;
interface
uses
Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,Dialogs,
StdCtrls,ExtCtrls,DXInput,DXSounds,DXClass;
type
TMainForm=class(TForm)
DXInput1:TDXInput;
Label1:TLabel;
Label2:TLabel;
AnalogMode:TCheckBox;
POVLabel:TLabel;
DXWaveList1:TDXWaveList;
DXSound1:TDXSound;
Label4:TLabel;
Timer:TDXTimer;
procedureTimerTimer(Sender:TObject;LagCount:Integer);
end;
var
MainForm:TMainForm;
implementation
{$R*.DFM}
procedureTMainForm.TimerTimer(Sender:TObject;LagCount:Integer);
begin
DXInput1.Update;
ifAnalogMode.Checkedand((DXInput1.Joystick.X0)or(DXInput1.Joystick.Y0))then
begin
{Analog}
Label1.Left:=Label1.Left+DXInput1.Joystick.X;
Label1.Top:=Label1.Top+DXInput1.Joystick.Y;
endelse
begin
{Digital}
ifisLeftinDXInput1.Statesthen
Label1.Left:=Label1.Left-10;
ifisRightinDXInput1.Statesthen
Label1.Left:=Label1.Left+10;
ifisUpinDXInput1.Statesthen
Label1.Top:=Label1.Top-10;
ifisDowninDXInput1.Statesthen
Label1.Top:=Label1.Top+10;
end;
ifisButton1inDXInput1.Statesthen
begin
DXWaveList1.Items[0].Play(False);
{Next,button1isinvalidateduntilbutton1ispushed.}
DXInput1.States:=DXInput1.States-[isButton1];
end;
POVLabel.Caption:=Format('POV(Pointofview):%d',[DXInput1.Joystick.Joystate.rgdwPOV[0]]);
end;
end.
测试操作我的xbox360手柄没有问题。
|