Как использовать joystick?
Как использовать joystick?
uses
MMSYSTEM;
var
MyJoy: TJoyInfo;
ErrorResult: MMRESULT;
begin
ErrorResult := joyGetPos(joystickid1, @MyJoy);
if ErrorResult = JOYERR_NOERROR then
begin
TrackBar1.Position := MyJoy.wypos;
TrackBar2.Position := MyJoy.wxpos;
RadioButton1.Checked := (MyJoy.wbuttons and joy_button1) > 0;
RadioButton2.Checked := (MyJoy.wbuttons and joy_button2) > 0;
end
else
case ErrorResult of
MMSYSERR_NODRIVER: ShowMessage('No Joystick driver present');
MMSYSERR_INVALPARAM: ShowMessage('Invalid Joystick Paramameters');
JOYERR_UNPLUGGED: ShowMessage('Joystick is Unplugged');
else
ShowMessage('Unknown error with Joystick');
end;
end;
Взято с сайта
var
myjoy: tjoyinfo;
begin
joygetpos(joystickid1, @myjoy);
trackbar1.position := myjoy.wypos;
trackbar2.position := myjoy.wxpos;
radiobutton1.checked := (myjoy.wbuttons and joy_button1) > 0;
radiobutton2.checked := (myjoy.wbuttons and joy_button2) > 0;
end;
Не забудьте включить MMSYSTEM в список используемых (USES) модулей