If your on windows10 Right click on the windows icon bottom left and a list will appear, go to Device Manager and it will give you another list and you will see Keyboard listed, click on Keyboard and a little line under it will appear with your keyboard, Now right click on that keyboard name, a little box will appear and you need to left click UPDATE Driver, it will then ask you where you want to search for the driver, the top box should say Automatically search for drivers, Click on this one and a green line will appear and go across the screen as it searches, this only takes a few seconds and it will either find and update the driver OR it will say the best driver available is already installed.
If the best driver is already installed just close all those boxes down and we start afresh.
If your keyboard works then doesn't work or disconnects when it feels like it there is a possibility the keyboard is fine and it is the USB ports which it is plugged in to which need sorting.
Keyboard Keeps Connecting & Disconnecting in Windows
If your keyboard keeps connecting and disconnecting, it might be due to the power management feature. One quick and effective solution to this problem is to run the keyboard troubleshooter. You can also fix this issue by uninstalling and reinstalling your USB controller drivers.
This again is done through the device manager in the same way as above but clicking on USB ports in device manager and seeing if any better drivers are working.
A lot of the time simply pressing the windows key bottom left and the space bar at the same time cures a lot of keyboard problems.
I am giving you a link to read up on, Now if it throws up a couple of pop ups just close them they are harmless and have a good read on keyboard problems as there is a few but normally it is a simple thing which when done you think Oh Yeh that was easy lol.
You can if you wish use the onscreen keyboard so if your keyboard is playing silly buggers whilst you try to sort the problem you do have a keyboard on the screen you can use hence not leaving you with no way to enter things.
It is simple and explained in the link how to turn it on and off when you have finished with it.
Good luck.
keyboard problems and answers.