RWAnalog is a program, which can handle analog input for Train Simulator using DirectInput.
Simply put, you can drive trains using a power lever from a flight stick, for example. The source code was designed to support other controllers too, even custom-built ones, with a bit of work.

You can find the program, its source code and a manual on the official GitHub repository. Simply extract the anywhere and run the application.

Because of its open-source nature, anyone with some C# experience can contribute to RWAnalog.
Have fun!