问题
I'd like to align an object in X and Y by eye using the mouse to move it into position. I can roll a solution by using various spin controls (or buttons) but it's messy and I got to wondering whether there is a control - like a joystick - that provides 2-axis control using the mouse and fires events at rates which vary depending on its position?
回答1:
Afaik Jedi (jedi apilib?) had a joystick header too. It is winapi, not COM, so no TLB involved
回答2:
Try NLDJoystick, an open-source component written by me and based on pure WinAPI (MMSystem.pas). It is downloadable from the SVN server here.
The interface:
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property AbsCenter;
property AbsMax;
property AbsMin;
property Active default False;
property Advanced default False;
property AxisCount;
property Axises;
property ButtonCount;
property HasPOV;
property ID;
property OnButtonDown;
property OnButtonUp;
property OnMove;
property OnPOVChanged;
property PollingInterval default 40;
property RepeatButtonDelay default 350;
property RepeatMoveDelay default 350;
property SuspendScreensaver default False;
property ThresholdFactor;
回答3:
Maybe you can make something like that yourself.
- Take a panel, and register on Mouse up, down and move events
- On MouseDown, set a boolean (fButtonDown) so you know that the mousebutton is pressed and save the X and Y coordinates of the mousepointer.
- On MouseMove, check if a button is down (fButtonDown) and move your object. The more your mousecursor is moved from its saved position, the faster you move.
- On MouseUp, set fButtonDown to false
The above is very primitive, but should work.
回答4:
I Googled for "joystick dll" and found countless. You can probably throw one of these into your project and then access its C API from Delphi by simply writing a TLIB header (or whatever it's called, haven't done this in a while) for it.
回答5:
You may use a DelphiX components. They are wrappers for DirectX and one of them wraps around DirectX joystick interface as far as I remember. It wraps in a Delphi-style so it is easy to use.
来源:https://stackoverflow.com/questions/2011999/is-there-a-delphi-joystick-control