Muscipula
Muscipula

Reputation: 55

How can I access a game controller via USB?

Problem
I am working on modifications to one of my applications that communicates with a telescope.

One of the most annoying problems due to nothing else but reckless poor design, is the GOTO controller and its keypad.

If anyone of you remember the Sinclair Spectrum you know what I mean. As well as the rubber keys, the crucial keys for guiding and slewing the telescope are awkward to locate when your eye is trying to adapt to the view.

All it takes is the wrong key and you spend another 30 minutes or so re-aligning the telescope.

Workaround
My solution is a game controller such as a wingman, it fits neatly into your hands and is easy to locate the buttons. Also there is no risk of reseting the mount.

Question
My question is this, how does Delphi interact with game controllers because tthere is no mention in the documentation? Otherwise how do I access a gameport when it is connected through a USB dongle?

Upvotes: 3

Views: 1079

Answers (2)

Mad Hatter
Mad Hatter

Reputation: 772

Delphi applications running on "NT" line operating systems (NT, 2000, XP, Vista, 7, 2003, 2008...) can't access hardware devices directly. Only drivers can, because the I/O ports required to access them can be accessed only by code running at the right IOPL level (which is 0 in Windows). There are some generic drivers available that open any I/O port (thus creating a security hole) that user code can call. But tt's far better to rely on device drivers, and use the HID API to interact with them. Windows will recognize most older devices (like the serial/game port Wingman), while newer USB ones or use the standard drivers that come with Windows, or come with their own. Once the system recognizes the devices, you can use them in a standard way with no need to dig in the low-level details.

Upvotes: 1

Ken White
Ken White

Reputation: 125728

Working with the game controller is part of the Windows API. JEDI's JVCL has a Human Interface Device (HID) constroller (TJvHIDDeviceController) component that does what you want.

Upvotes: 6

Related Questions