A "nice" cordless keyboard that doesn't work may have an internal battery that isn't being re-charged. Or, if replaceable dry cells are used, they may be "dead" or corroded. Please tell us the name and model of the keyboard.
Do not store batteries in unused electronics equipment. Even if something is used on a regular basis, like a TV remote control or a wireless mouse, check the cells at least once a year for corrosion. Check more often if you live near salt water. Corrosion usually shows up as an exterior white powder, usually on the negative terminal of the dry cell, that eventually will penetrate to the interior of the cell and release a corrosive electrolyte. Unless the battery compartment is hermetically sealed (you would have do that yourself!), whatever "gunk" escapes from one or more corroded cells will wreak havoc with the electronics those cells are supposed to power.
I have a Logitech K-800 wireless, lighted keyboard that uses a little "dongle" plugged into a spare USB port to communicate with the keyboard. The dongle seems to be "paired" with the keyboard, because another dongle for another K-800 that I own does not appear to be interchangeable. Depending on how you acquired that "nice" keyboard, the dongle that makes it cordless may not be the original dongle that was paired with your keyboard, but that should not prevent the keyboard lights from working. Which is why it is helpful to us, who are trying to help you, to know what make and model keyboard you have.
The internal, re-chargeable battery in my K-800 keyboard is only recharged when a short cable is used to connect the keyboard to either an open USB port or to a "wall-wart" cell phone charger. A nice feature is the light under each key comes on when fingers are brought near any of the keys and then the key lights go off when the keyboard is not in use. Because of this power-saving feature, I can generally run for several months without using the USB cable to charge the internal battery. If I wait too long to charge, the keyboard simply quits working. You would think I would notice the keys not lighting long before the keyboard quit working, but I generally use my keyboard in well-lit room that mostly "washes out" the relatively dim light visible through the injection-molded plastic key caps. I only appreciate the key lights when the room lights are dimmed, and I am practically typing in the dark!
Yep. It used to be LOT worse before alkaline cells became available. I can remember when Leclanché (zinc-carbon) cells, made with a cylindrical zinc anode (that also served as a case) and a carbon-rod cathode running down the cylindrical axis, could leak in just a few days or a few weeks of heavy use. They also tended to self-discharge, even if left unused on the shelf. They were especially BAD for use in flashlights because of the self-discharge and rapid corrosion problem.
Then along came alkaline cells, and better ways to build them, so that leakage was reduced to practically nothing and shelf life extended to ten years. But even the best name-brand cells are susceptible to corrosion and eventual leakage, so inspect the cells that are in use and perhaps record the date they were first placed into service. Even if a cell "measures good" under load (unloaded voltage measurements are not a reliable indication of remaining charge availability) it is a good idea to replace every year cells that have been service for at least a year, even if the equipment the cells power still works properly.