Under DOS, it was possible to directly access these ports. However, Windows 95 and above forbid direct hardware access. Therefore, this page exists to help get around windows.
Generic References
Delphi
Windows API support is defined in rtl\win\mmsystem.pas
The following code snipet is from The Unofficial Delphi Developers FAQ.
uses ... , mmSystem; 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;This snippet is pretty good, but only one radio button can be set at a time. Also note that the position range is 0 to 65,535 when calibrated. Be sure to set the trackbar max values appropriately. (On my test system, the center position is 38,500 x 26,900.)
Using a Message Handler
type TMMJoyStick = packed record Msg: Cardinal; // The message ID Buttons: Longint; // The wParam XPos: word; // The lParam YPos: word; Result: Longint; end;There is one interesting inconsistency
procedure MMJOY1BUTTONDOWN (var LocMessage: TMMJoyStick); message MM_JOY1BUTTONDOWN; procedure MMJOY1BUTTONUP (var LocMessage: TMMJoyStick); message MM_JOY1BUTTONUP; procedure MMJOY1MOVE (var LocMessage: TMMJoyStick); message MM_JOY1MOVE; // ButtonDown and Move are not shown, they just call ButtonUp procedure TForm1.MMJOY1BUTTONUP (var LocMessage: TMMJoyStick); begin trackbar1.position := LocMessage.ypos; trackbar2.position := LocMessage.xpos; Edit1.Text := IntToStr(LocMessage.ypos); // so you can see Edit2.Text := IntToStr(LocMessage.xpos); // what is happening CheckBox1.checked := (LocMessage.Buttons and joy_button1)>0; CheckBox2.checked := (LocMessage.Buttons and joy_button2)>0; end; procedure TForm1.FormCreate(Sender: TObject); var myJoyCaps: TJoyCaps; begin joyGetDevCaps(joystickid1,@myJoyCaps, sizeof(myJoyCaps)); // for test joySetCapture(self.Handle, joystickid1, 100, true); end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin joyReleaseCapture(joystickid1); end;
Windows API
joyGetDevCaps joyGetNumDevs joyGetPos joyGetPosEx joyGetThreshold joyReleaseCapture joySetCapture joySetThreshold