CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2004
    Posts
    132

    is it possible to simulate a joystick?

    I am building a game controller that will be connected to the PC through a com port, and maybe later usb. I want to be able to simulate a joystick as one of the options. Is there some way to do this with VB6?

  2. #2
    Join Date
    Dec 2006
    Location
    Pune, India.
    Posts
    579

    Re: is it possible to simulate a joystick?


  3. #3
    Join Date
    Aug 2004
    Posts
    132

    Re: is it possible to simulate a joystick?

    Quote Originally Posted by Shaikh.Riyaz.a
    I think that api is to read a joystick. I will be reading my own device through the com port and I want to convert the readings and output them as joystick moves. So I need to simulate a joystick without actually having one plugged in.

  4. #4
    Join Date
    Dec 2001
    Posts
    6,332

    Re: is it possible to simulate a joystick?

    I'd have to guess that a program which expects a joystick will be ultimately relying on the API, be it directly or indirectly. There are apparently USB controllers though, but I don't know if the drivers are designed to simulate a joystick to the point of sending the signals in such a way as to appear as a standard game port controller.

    Since the game port is so easy to use, I'm wondering why you'd want to use a COM port instead. Can you elaborate on what you are trying to do?
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  5. #5
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,452

    Re: is it possible to simulate a joystick?

    My suggestion is to use the API. Write your own program to work with a joystick. Use the Spy++ tool to monitor the messages being sent to your window. Once you know what the messages the joysick send, use the SendMessage API to mimic the joystick.

  6. #6
    Join Date
    Aug 2004
    Posts
    132

    Re: is it possible to simulate a joystick?

    Quote Originally Posted by WizBang
    I'd have to guess that a program which expects a joystick will be ultimately relying on the API, be it directly or indirectly. There are apparently USB controllers though, but I don't know if the drivers are designed to simulate a joystick to the point of sending the signals in such a way as to appear as a standard game port controller.

    Since the game port is so easy to use, I'm wondering why you'd want to use a COM port instead. Can you elaborate on what you are trying to do?
    I have an MCU that is reading from a digital compass and an accelerometer. It will do some number crunching but mostly it will just send raw data to the PC through the com port. My VB program will then convert the data to optional outputs, either simulating keypresses, mouse movements or joystick movements. I can do the keypresses and mouse movements but I have no idea how to make the pc think it is a joystick.

    Last night I found a virtual joystick called PPJoy and had a play with that and when you add a virtual joystick windows starts up the "found new hardware" wizard and adds it as a joystick. So I know it can be done, but I am not sure how. I have a feeling I need to write my own driver.

    Quote Originally Posted by sotoasty
    My suggestion is to use the API. Write your own program to work with a joystick. Use the Spy++ tool to monitor the messages being sent to your window. Once you know what the messages the joysick send, use the SendMessage API to mimic the joystick.
    Thanks, I'll have a look at your suggestions. Can someone give me a hint on where to get spy++ and how to use it? From what I can find it is a tool for Developer Studio 6 which I don't have. I only have VB6 and the Visual Studio Installer.
    Last edited by Taipan; June 11th, 2007 at 05:08 PM.

  7. #7
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: is it possible to simulate a joystick?

    It comes with most versions of VB6, but if you don't have it on the cd (optional addon) then you can download a replacement. just google for it. someone else wrote one that is identical. I used that before I found it on the CD...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Join Date
    Dec 2001
    Posts
    6,332

    Re: is it possible to simulate a joystick?

    You can get example code for detecting joystick signals here: http://allapi.mentalis.org/apilist/joyGetPos.shtml

    I've never seen anything to suggest that the joystick port is bidirectional, but I know there are MIDI APIs for both sending and receiving.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  9. #9
    Join Date
    Aug 2004
    Posts
    132

    Re: is it possible to simulate a joystick?

    Quote Originally Posted by sotoasty
    My suggestion is to use the API. Write your own program to work with a joystick. Use the Spy++ tool to monitor the messages being sent to your window. Once you know what the messages the joysick send, use the SendMessage API to mimic the joystick.
    Slowly puzzling my way through this. I wrote a program that has a timer that reads joystick information and displays the X, Y, Z coords in a text box. But I can't figure out how to see the messages that is being sent to it from the joystick. I have spy++ and I select my program and view the messages but I can't see anything that would be coming from the joystick. I think I am only viewing messages being sent from my program. How would I view messages being sent to it?

  10. #10
    Join Date
    Dec 2001
    Posts
    6,332

    Re: is it possible to simulate a joystick?

    Quote Originally Posted by Taipan
    Slowly puzzling my way through this. I wrote a program that has a timer that reads joystick information and displays the X, Y, Z coords in a text box. But I can't figure out how to see the messages that is being sent to it from the joystick. I have spy++ and I select my program and view the messages but I can't see anything that would be coming from the joystick. I think I am only viewing messages being sent from my program. How would I view messages being sent to it?
    Basically, the information isn't being sent to your app's window per se. The API function queries the joystick, and returns the data. Even if there's a way of simulating this for your app, it isn't the same as having the OS think a joystick is connected and being used.

    Maybe these can help:
    http://bcb-tools.com/TDx_Library/Tut...tm#DirectInput
    http://www.koders.com/cpp/fidD436700...AFD8D80A9.aspx
    http://www.autohotkey.com/docs/Hotkeys.htm
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured