Detach and Reconnect:
Detach the keyboard, wait 10 seconds, and snap it back on firmly.
Clean the Connectors:
Use a soft, dry cloth to wipe the magnetic pins on both the keyboard and the Surface, ensuring no debris is obstructing the connection.
Force Restart:
Press and hold the power button for 20 seconds. If you see the logo screen appear after a few seconds, continue holding for the full 20 seconds until you see it again.
Test in UEFI Mode:
Press the Start and Volume Up button on top of the Surface, hold until the UEFI screen appears, if the keyboard works there then it's a Windows/ Software related issue.
See: