I have also been struggling with this problem for some time, it’s very frustrating!
However, I watched a YouTube video tonight which seems to have come up with a simple solution that has sorted it for me.
Even when the keyboard isn’t working the “Command” button seems to still work. Press it a couple of times then use “Command + Tab” to cycle through the open Apps and, low and behold, it works.
This is the first time for months that my keyboard has worked ... don’t know how long that will last though!
Give it a try and report back and let us all know if it works as well for you as it seems to have for me.