For me it's a question of whether I like it or whether it helps me solve another problem (the more I'm interested in that other problem, the better).
Curiosity is what got me into it and then got me deeper into specific areas.
At first I was just using the computer, mostly playing games. Then I got interested in how those games were made, how to draw objects on the screen and have them move around. So I learned BASIC.
Then I realized BASIC was not the right choice is it was too slow for drawing, especially for animate objects (and that was on the Z80 running at a few MHz, a machine a thousand times slower than we have nowadays). So I learned machine code and assembly and got my programs significantly faster.
Later I got interested in many other aspects of software and hardware and learned a whole lot of other things (Pascal, 3D graphics, devices, C, OSes, other CPUs, embedded, DSP, algorithms, virtualization, compilers, C++, etc etc). Some math and physics background helped with things a bit (although, I must say, to start you rarely need anything more advanced than what they teach you in high school).
There has always been something that I wanted to know how it worked or worked unbelievably (almost magically) well.
This is how I learned English, which I'd never consciously intended to. School and uni English instruction was piss poor and there wasn't English in my daily life otherwise. But through programming I got the hang of it. I wanted to learn more about programming and so I read lots of code and documents in English and I talked to people online about programming. Seeing quite a bit of confusion and misunderstanding in those online conversations, all resulting from my poor language skills, I made some effort to improve in various areas of the language (initially, just the grammar and some key vocabulary) by diving into the dictionary and grammar references, doing what my language instructors should've done or should've gotten me doing, studying and learning without thinking of it as such. After all, reading a CPU manual and an "English manual" and trying to make sense of things in there is not all that different.
English then helped me with further studies and work. And it opened to me a whole new world of literature and art. It's very enjoyable to read or watch things in original English, much better than translated. And I fell in love with American standup.
This in turn sparked in me a general interest in languages. And so I did learn some Spanish too, which is helpful sometimes.
And I only wanted to know how those old games were made.
So, again, if it's something you're interested in or something through which you can get something else, it is pretty natural to do it, sometimes even without clearly realizing what you're doing. I'll learn this because it'll help me with that, no biggie. And, of course, you learn by doing.