Actually, there's always gravity present but it just depends on how close/far away you are from any nearby objects. If you're in the middle of nowhere, then it's more likely that you won't be as affected by the gravity of another planet or something like that since you're far enough away to not be attracted to it so yeah, you're basically stuck travelling in one direction at a constant speed unless someone/something interferes with you

(or at least that's what I learned, please don't rely on me for knowledge because I know nothing)