The lifespan of a computer keyboard depends on the quality of the keyboard and how often the keyboard gets used.
Cheaper keyboards should last up to 5 years with a lot of use typing while higher end and higher cost computer keyboards could last up to 10 years or more with a lot of use.
If you only use the keyboard occasionally then even the cheaper keyboard could last you as long as 10 years.
I use my my keyboard a lot for typing because I have a blog that I write blog posts daily for and I write long detailed blog posts so my keyboards get used a lot and they typically start getting hard to type on by 4 years so I replace the keyboard with a new one every 4 to 5 years or whenever the keys start getting hard to press down.
So with lots of use expect 4 to 5 years but with occasional use the keyboard could last you up to 10 years.