It seems that instruction books for beginning students often emphasize holding your hand in a particular position for an extended period of time, with your individual fingers positioned over five notes, usually five adjacent white keys.
I don't know how useful this is for instruction, but I know it is sometimes done that way.
In more advanced playing, you will sometimes use adjacent fingers to play adjacent notes, but you will also move your hands a lot. You might play many notes in a row while moving your hand to a new position for every single note.
You may also play chords where you strike several notes at the same time with several fingers of one hand. The notes often are not all within one range of five consecutive white keys, so you will need to open the gaps between your fingers in order to reach all the notes.
When I'm playing, any of the following might happen:
I might just have struck one white key with my thumb. Seeing that the next note is nearby and there are not far-away notes to play very soon, I use the finger that is already nearest the new note in my relaxed hand position, which happens to be the middle finger. The fact that the two notes are on adjacent spaces between lines of the staff might be a reminder to me that this fingering will likely work. I am not thinking to myself, "This is D, this is F, F is two notes above D, the middle finger is two fingers away from the thumb, use the middle finger." It is more a matter of experience that notes that "look" like that will be easily played with these two fingers.
I might just have struck one white key with my thumb. Seeing that the next note is nearby but that there are much-farther-away notes I have to play very soon, I choose to strike the next key with my index finger (next to the thumb). In order to strike that key with my index finger, I move my hand to the right without really thinking about the fact that I am moving my hand.
I might just have struck one white key with my thumb. Seeing that the next note is nearby but that I will soon have to play notes to the left of the thumb-note, I use my ring finger or pinky on the next note. Sooner or later during this particular sequence of notes I will move my hand to the left, but I think about this so little while actually doing it that I don't even know what to tell you about exactly when I will move my hand.
If this is a piece I have played before, I may recall that I want to strike the next note with a particular finger because it will help me better play the notes that follow after that one. I am not calculating the distance between keys, the distance between my fingers, the position of my hand relative to the keys, or any of those thiings; I simply recall that for this note in this particular piece at this particular time in the piece I want to use this finger.
Sometimes I find that the editor of the sheet music has helpfully written a number next to the note, for example 4 to tell me to use the ring finger to strike that note, so I use the finger recommended by the editor. This is a bit like the previous example, except that I have not memorized the use of this particular finger for this particular note of this particular piece, I am just assuming that the editor worked out that this particular finger works well.
And sometimes when I'm sight-reading or playing a piece I have not played in a while, I choose to strike a particular note with a particular finger and then find out a few notes later that this did not work very well for playing the following notes.
This makes playing those notes awkward. I might go back to that part of the piece and try it again with a different finger, and if I practice the piece that way I might learn to use that finger, at which point it becomes like the example a couple of paragraphs earlier.
If you're still at the level of study where you have to think about which finger to use for F after playing D with your thumb, you're not yet at the level of study where trying to use all the techniques in the paragraphs above is going to be very useful to you. But if you have music with the fingerings indicated by numbers, you can still follow those fingerings.