Solved

Generating joystick messages

Posted on 2006-10-22
2
432 Views
Last Modified: 2012-08-14
I have a need to generate Windows joystick messages. Basically I have an industrial analog input card, and need to transmit the data to Macromedia Director. The standard Windows joystick input is not reliable enough for us to connect directly to that (there's a lot of jitter on the input), hence the need for a 'real' analogue card.

My plan is to write the code in Delphi to read the input card (no problems doing that), and then send joystick X axis commands. Director can read that information easily. Getting Director to do this directly (so to speak) would be a bit of a nightmare I'm told.

So, anyone got any ideas on how I can generate joystick messages (a bit like you can generate mouse or keyboard events)? I've looked all over the net and MSDN and can't find anything.

Martin
0
Comment
Question by:passpics
2 Comments
 
LVL 19

Expert Comment

by:MerijnB
Comment Utility
here http://sheepdogguides.com/dt4i.htm there is some information on TMMJoystick (multimedia joystick message). You could try to send this either directly to Director, or try to broadcast it.

Other option (maybe, dunno) could you send arrow key-presses, that would probably easier to achieve.
0
 
LVL 9

Accepted Solution

by:
bernani earned 250 total points
Comment Utility

Hi

I believe you could maybe use the unit Joystickex.pas to download from

http://www.torry.net/vcl/system/joystick/hgjoystickex.zip.

I reproduce the content of Joystickex.txt so you can decide to download or not:

"
Joystickex.Pas; V1.0

Copy rights:  Heiko Groschupp; h.groschupp@media-ag.com; Germany

Status : E- mailware (free tu use, but send me an E-mail, if you do so or if you make changes)

Disclaimer
----------
THIS SOFTWARE IS PROVIDED BY HEIKO GROSCHUPP "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

Purpose:

Joystickex is a nonvisual component to implement capturing of joystick input to your app.
It uses no timer to poll joystick informations but is driven by windows messages. That means as soon as windows notifys a joystick event it is sended to that component and and will be processed at the same time.
This component was testet with D4 and WIN98 should run with other Win32 and D2- D5 too.

Interface:

    // Get Infos about device
    Function GetDevices  :Byte; --> returns Number of connected devises
    function GetButtons :Byte; --> returns Number of Buttons of the joystick at the selected Gameport

    // Set to or set out of Operation
    procedure disableJoystick; --> capturing of the joystick is disabled
    function EnableJoyStick :Boolean;--> initialisize joystick capturing; returns FALSE if failed (i.e. no joystick connected)

   // Calibrating functions
   function CalibrateCenter : Boolean; --> set the internal center values to current x/y- values
   function BeginCalibrateRange  : Boolean; --> component is set to calibrating mode; change s of x/x range are stored every time the values go higher/ lower then they where before
   procedure StopCalibrateRange; --> sets component to normal mode

   // System dialog
   procedure SysDialog; --> executes the windows Dialog for Joystick properties

   // save settings
   procedure SaveCalibration; --> stores the internal calibration datas to the app. directory (INI- file)
   procedure LoadCalibration; --> loads the internal calibration datas from INI-file in the app. directory
 
 
properties


    property GamePort :TGameport  --> spezifies the port
    property Polling: Boolean --> Windows sends continiously messages  in the interval you can spezify (min 10ms; max 1000ms)
    property Interval : integer --> see above
    property Center : TPoint --> gives you the value of internal Centerpoint (read only);
    property EventThreshold : Real; spezifies the amount of movement, which needs to be done with the joystick in the spezified interval above (0.01 -10 in per cent of maxvalues of internal range)
    property Scaled : Boolean; if true you get negativ/ positiv values with the maximum like you spezify below otherwise you get value mostly in the range of -32767 - 32767

    property XScaledBy :TScalevalue (TScalevalue = 1..32767) if you spezify i.e. 100 you get  -100 for left side and  and +100 right side (Center := 0)
    property YScaledBy :TScalevalue (TScalevalue = 1..32767)
    property ZScaledBy :TScalevalue (TScalevalue = 1..32767)
    property CalAutoSave :Boolean; if true component saves values of internal range to a Ini- file if component is destroyed;
    property CalAutoLoad :Boolean; if true component loads values of internal range from a Ini- file if component is created;
   
    // Read onlys
    property MaxLeftUP :TPoint;
    property MaxRightDown :TPoint;
    property MaxZ :integer;
    property MinZ :integer;
    property NumButtons :Integer;
   

 //Events
    property OnButton1_Change: TButtonNotifyEvent read  FOnButton1_Change Write  FOnButton1_Change;
    property OnButton2_Change: TButtonNotifyEvent read  FOnButton2_Change Write  FOnButton2_Change;
    property OnButton3_Change: TButtonNotifyEvent read  FOnButton3_Change Write  FOnButton3_Change;
    property OnButton4_Change: TButtonNotifyEvent read  FOnButton4_Change Write  FOnButton4_Change;

    property JoyZMove :TJoyZMoveEvent read FJoyZMoveEvent write FJoyZMoveEvent;
    property JoyMove : TJoyMoveEvent read FJoyMoveEvent Write FJoyMoveEvent;


MISC

containing files of this upload:

JoyStickEx.pas
JoyStickEx.dcr
JoyStickEx.txt

simple Demo project

provided as zip- file


If you like to make changes to this code feel free to do so but send me an E-mail with your changes. Thanks:-)

______________________________

PS: works on WinXP without problem (even if not fully and deeply tested as I don't use joystick).

Hope this can help.

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now