keyboard can use both
No, there was only Direct Current from batteries but no AC electricity as we know it today.
Something powered by household electricity rather than batteries
Cells and batteries are portable and can be taken anywhere you go. Main electricity is stationary
Touching bare, live, contacts, connected to mains electricity will give you a nasty shock which could be fatal. Your house circuits have protection using circuit breakers, fuses and RCDs.Large batteries have the capacity to deliver very large currents if shorted out, which can cause fires and may explode, showering acid and/or chemicals all over the place.
The source for an electromagnet can be any electrical supply. Batteries or derived from the mains, using a transformed and rectified supply.
Portable devices that do not consume large amounts of power can be run on batteries. Some battery powered devices can also be powered by mains - running a 'battery eliminator' - to save from having to purchase batteries. Devices that consume large amounts of power are usually best powered by mains.
Electricity supplies in the US contain about 19 percent nuclear generation, so anything which uses electricity from the mains uses nuclear power
Mains electricity is nothing but main source of power in an installation. From the mains the power is then branched out to different end usage.
Everything that is plugged into the mains socket and switched on will use electricity even if it's a battery charger with no batteries in. So yes they do draw electrical power from the mains.
A TV, computer, radio ,phone , fan
Batteries do not produce electricity, they only store electricity.
The first difference is that mains power is AC (Alternating Current) whereas batteries are DC (Direct Current). The second difference is the amount of available amperage; mains have the capacity to deliver higher current for an indefinite amount of time, where batteries will drain faster the more current is pulled. Your normal A/AA/C/D/9V batteries only produce 500 milliamps (1/2 an amp) at their nominal voltage (1.5 or 9v). Mains current (for the U.S.) is 110 or 220 volts in residential. Commercial mains, such as in factories, can be 110, 208, 220, or 440 volts. A big difference between residential and commercial electricity is the available phasing. But that's another discussion.