As peripherals, the keyboard is not truly affected by viruses. But if your device gets infected, it can affect the behavior of your keyboard. So installing reliable antivirus software with real-time protection should keep your system safe.