Hello folks.

I have done a good amount of research and I'm still unable to determine how I can perform real emulation of a joystick.
What I found on the web was using the mouse movements to simulate a joystick that moves an imaginary little ball.

No, what I wish to do is to emulate a real joystick, programmatically.

The reason is that I'm working with a hardware device for disabled people, this device allows a disabled person to access the PC and I want the device together with my code to replace the joystick.

Basically, the disabled person uses this device in 'joystick' mode which will trigger/produce/generate the same output that a joystick outputs to Windows; to perform a real emulation of a standard joystick.

Thank you for your time!

Can you clarify for me, do you have some custom hardware which you would like to interface with the PC as if it were a joystick, or do you want to write software which will create output as if it were a joystick?

I would like to create software that would create output as if it were a joystick.
(The hardware already goes into some software hoops and loops in order to be operable, now we just need to be able to write code that produces output as if it were a joystick).

Thanks a lot for paying attention to my question, questions spiral down the list quickly here.

It doesnt look like what you wanna do is easy, if possible. I'm not suprised, after the hoops i had to jump through to code for a USB device : /
It look slike you may need to develop a virtual HID device driver. It's way out of my depth so i'm gonna bow out and let someone who knows what their doing point you in the right direction. Sorry and good luck :)

Oh, I didn't think it would be that bad.

I thought it would be kinda similar to how we can intercept keyboard hooks; you know figuring out what kind of messages does a joystick send to Windows and imitate that.

Thank you for your time! Do you know a particular person who might be able to help me?

Ignorant of the subject am I (definately not my forte) , but it sounds like you might need to write your own device driver to emulate the device. I might not be giving you any information here you haven't already considered; however, I ran across these links and figured I would pass them on:

Forced FeedBack...

Capture directinput device...

What you might also look for is a keyboard/joystick emulator, that could provide more insight into directly communicating with and emulating the driver interface.

Thanks a lot for the useful links. The path is clearer now, although it sounds very challenging!

Of course, any more advice and directions are welcome.

you can always check out Windows Driver Kit. I remember seeing an article that mentioned vhidmini driver as a good starting point for writing custom joystick drivers but i think that was an older version of WDK : / There is mention somewhere of hidusbfx2 as a good starting point though :)

Had a read around to try and find somethign useful for you, but all i could find were lots of people who want virtual joysticks. If you write this as a well constructed, feature rich module you could probably market it ;)

Thanks a lot, man! It does not sound so bad to try and make the driver myself, I never wrote any driver before, though.

I'm trying to gather all possibilities and ways to do it, and try to research the best method to do it. If anyone else has a good idea, please share it!

>> I have done a good amount of research and I'm still unable to determine how I can perform real emulation of a joystick.
What I found on the web was using the mouse movements to simulate a joystick that moves an imaginary little ball.

I don't know that a driver would be in order for this approach. What are you trying to emulate with a joystick that you are unable to do with a mouse? Also what type of canvas/form will this joystick be working on -- or will they be using it instead of a mouse for controlling all human input?

I'm trying to understand if you have a form with various objects on it that you are wanting to do something with -- or if you are doing something else? Can you include a screenshot or a mock-up of what you will be using this joystick for?

A mouse can effectively simulate what a joystick does as-is for the most part. When I think of the uses for a joystick over a mouse I imagine games like flight simulators. Ignoring the oriontation of vertical direction for movement of the joystick it should be the same as a mouse (some people like to invert controls on joysticks for flight games where when you pull back on the stick the plane goes up. However if you're playing a non-flight game where you need to target objects I imagine that an inverted joystick would be highly annoying. It depends on the user.)

PS/2 is by nature a simpler device than USB. With PS/2 a joystick just repeats mouse movement. IE pulling down on the joystick 1/2 way sends a signal of relatively slow movements like pulling your mouse down. Pulling the joystick down all of the way sends a series of fast mouse movements. The real difference here is with physical real-estate on your desk. In a flight game if you were pulling back on a joystick (moving the mouse towards you) and you hit the end of your mouse pad you have to pick up the mouse and put it at the top of the pad, you can't slide it forward or your plane will nose divce. A joystick will simply keep repeating the downward movement.

Now with a USB joystick the mechanism for sending the OS messages about HID movement is roughly the same concept but they go about it different ways. Instead of a repeating-speed of movements with PS/2 you can query the joystick with USB to get distance away from 0degrees, where the yolk is cenetered. Knowing the distance away from centered allows you to perform "speed" calculations in that direction and you can calibrate it however you want.

All of that being said -- there are only specific situations I can think of where you can't emulate a joystick with a mouse. But keep in mind the user experience with the two different HIDs will be different. It is much harder for most people to target objects with a joystick as opposed to a mouse, and you can't react as fast with accurate targeting (think of a first person shooter).

Try explaining what you are trying to accomplish a little bit more.

[edit]
Is this program like Marble madness?
[/edit]

I do my own BCI software development, and now I'm working with a company that is specialized in BCI systems (Brain Computer Interfaces). Mouse emulation using brainwaves has already been done (Both my version and theirs), so the mouse is totally covered for disabled people.

However, I was asked to provide joystick emulation. Sure, it may not be of immediate necessity since we already emulate the mouse (all directions and clicks), but we wish to do it for the instances where using mouse controls isn't fitting, just like your example of flight simulators. Our method of emulating the mouse is done via activating certain brainwaves; some of these waves can be easily triggered in a continuous manner, so it can easily fit joystick movements, that's number one.

Number two is that using brainwaves to emulate the joystick is an important training method on brainwave control for the disabled user.

You have brought light on the fact that a mouse can replace a joystick except when there is need for continuously moving in a certain direction (Mouse movements ending at the mouse pad limits), but our method of mouse emulation through brainwaves actually allows us to keep a certain direction suppressed continuously. Do all games allow for mouse control (so that our un-hindered mouse emulation is enough) or is the joystick a requirement?

That was regarding our need for the joystick emulation.

Now, regarding implementing it, if viable:
It was my belief that since a game corresponds to most joysticks; there has to be some joystick interface for Windows that reads what the joysticks say and delegates it to the games.

This is what I'm trying to reach, how can I send the same messages to Windows that a joystick does to inform Windows about joystick actions? If I can produce the same messages then I have emulated the joystick.

Our application runs in the background, and by choosing the proposed joystick mode, the disabled user can play joystick games using his brainwaves for joystick control, we're talking games like MS Flight Simulator and its brethren.

One more thing, you said PS/2 joysticks basically work by sending mouse direction messages, repeating them in a fast pace when the joystick is pulled all the way down? We can do this acceleration control using brainwaves for mouse control, if so this might mean emulating a joystick is even more redundant assuming joystick games accept the mouse as a substitute.

Thank you for your replay.

>> I have done a good amount of research and I'm still unable to determine how I can perform real emulation of a joystick.
What I found on the web was using the mouse movements to simulate a joystick that moves an imaginary little ball.

I don't know that a driver would be in order for this approach. What are you trying to emulate with a joystick that you are unable to do with a mouse? Also what type of canvas/form will this joystick be working on -- or will they be using it instead of a mouse for controlling all human input?

I'm trying to understand if you have a form with various objects on it that you are wanting to do something with -- or if you are doing something else? Can you include a screenshot or a mock-up of what you will be using this joystick for?

A mouse can effectively simulate what a joystick does as-is for the most part. When I think of the uses for a joystick over a mouse I imagine games like flight simulators. Ignoring the oriontation of vertical direction for movement of the joystick it should be the same as a mouse (some people like to invert controls on joysticks for flight games where when you pull back on the stick the plane goes up. However if you're playing a non-flight game where you need to target objects I imagine that an inverted joystick would be highly annoying. It depends on the user.)

PS/2 is by nature a simpler device than USB. With PS/2 a joystick just repeats mouse movement. IE pulling down on the joystick 1/2 way sends a signal of relatively slow movements like pulling your mouse down. Pulling the joystick down all of the way sends a series of fast mouse movements. The real difference here is with physical real-estate on your desk. In a flight game if you were pulling back on a joystick (moving the mouse towards you) and you hit the end of your mouse pad you have to pick up the mouse and put it at the top of the pad, you can't slide it forward or your plane will nose divce. A joystick will simply keep repeating the downward movement.

Now with a USB joystick the mechanism for sending the OS messages about HID movement is roughly the same concept but they go about it different ways. Instead of a repeating-speed of movements with PS/2 you can query the joystick with USB to get distance away from 0degrees, where the yolk is cenetered. Knowing the distance away from centered allows you to perform "speed" calculations in that direction and you can calibrate it however you want.

All of that being said -- there are only specific situations I can think of where you can't emulate a joystick with a mouse. But keep in mind the user experience with the two different HIDs will be different. It is much harder for most people to target objects with a joystick as opposed to a mouse, and you can't react as fast with accurate targeting (think of a first person shooter).

Try explaining what you are trying to accomplish a little bit more.

[edit]
Is this program like Marble madness?
[/edit]

Not to answer your question but for background information I have on HID ---

For games, as far back as I can remember, they always allowed any type of input. Keyboard, mouse, track-ball, or joystick because to Windows it is all the same thing -- a mouse movement. Even with flight simulator if i'm not mistaken when you press the down arrow it is effectively like pulling the joystick back. And when you released the down arrow it stopped the plane from climbing, ie you let go of the joystick. In this sense all HID are doing the same thing -- sending a downward mouse movement. Every game I can recall that was targeting sensitive allowed for in-game calibration, sensitivity, and repeat-speeds.

I used to play counterstrike (rock on!) and I have a Logitech MX510 mouse. Now in windows I can go to the control panel and configure the mouse speed (see attached). I can also enable the "Enhance pointer precision" option which is mouse acceleration. That means when the mouse moves small distances it picks up speed as configure by the pointer speed. If the OS detects i'm moving long distances then it accelerates the movement of the mouse so it goes even faster yet. This is very handy since I have a 24" monitor and it takes a little while to get across my desktop.

Now my mouse also has a few extra buttons -- so I need to installed the Logitech drivers. Logitech thinks they can do a better job than Microsoft at controlling the mouse speed so they also have options inside of the driver from mouse speed and acceleration.

Now counterstrike also has an option for mouse speed (i don't think they have acceleration, and you probably don't want it for a first person shooter). So in-game a movement of the mouse goes through multiple processing points before it hits the game:

Windows Mouse Speed, Logitech Mouse Speed, Windows Acceleration, Logitech Acceleration, In-Game mouse speed.

I'm taking a guess based on the feel of the game that counterstrike was well aware of mouse speed/acceleration and shut it off for in-game play, but not the logitech driver. If I had my logitech driver running when I started up the game the mouse was crazy sensitive and I couldn't even shoot my own foot... so I always had to shut it off before I played a game.

Now back to your question ---

I guess i'm not really sure why your mouse approach won't work. I think it is the same as a joystick more or less custom features.

Here is a sample project that basically converts a mouse to a joystick. I'm not sure how brainwave activity can be changed, ie how much precision a person has in the fine grain movements of the mouse:
http://www.c-sharpcorner.com/UploadFile/ldrolet/MouseStick06132005031337AM/MouseStick.aspx

commented: Very helpful! +6

That's so good to hear, it means we got joystick control covered with the mouse emulation.

I have seen that mouse to joystick simulation, it wouldn't do me any good. However now I can report back to the company to inform them of the viability of the mouse emulation algorithm to replace the joystick.

Thanks a lot, everyone!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.