I'm assuming because the locomotive operated by the player isn't on a timetable, the railroad switch control won't (necessarily) be set for you to go the way you want.
My suggestion is to allow the player to press and hold the left or right arrow key while operating the locomotive to select the desired direction at the split. After we are on the desired track, release the arrow key. Simple.