开发者

Is there a Delphi 'joystick' control?

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)开发者_C百科 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?


Afaik Jedi (jedi apilib?) had a joystick header too. It is winapi, not COM, so no TLB involved


Try NLDJoystick, an open-source component written by me and based on pure WinAPI (MMSystem.pas). It is downloadable from GitHub.

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;


Maybe you can make something like that yourself.

  1. Take a panel, and register on Mouse up, down and move events
  2. On MouseDown, set a boolean (fButtonDown) so you know that the mousebutton is pressed and save the X and Y coordinates of the mousepointer.
  3. 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.
  4. On MouseUp, set fButtonDown to false

The above is very primitive, but should work.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜