Everything you do is from learned behavior.
When I was a little kid, I heard wonderful music, played by my mother on an old piano in my home.
I had no idea how to repeat the lovely sounds I heard, but I figured out that the sounds were a result of a succession of keys that I pressed that actually sounded like the tune my mom recently played!
And this is how I learned to play by ear.