Turn off the tablet. Use a pencil eraser to gently rub the gold contact points on the back of the keyboard and the bottom edge of the tablet. Follow up with 91% isopropyl alcohol on a cotton swab. Do not use water.
The gold connectors on the tablet or keyboard are bent or dirty. Phase 1: Troubleshooting Software and Connections hp elite x2 keyboard repair
Sometimes you just need an expert. Here are your best bets: Turn off the tablet