keys repeat on bluetooth keyboard
When I leave my computer running for a few days, a weird thing happens with the keyboard. First, it gets very slow, so that typing in my password when it is waking takes just under one second per keystroke. Then, once it's unlocked, several of the keys repeat, and it doesn't seem to matter which keys these are. If I want to type in the word "wanted," it might come out (slowly) as "wwwwwwwwwwwanttttttttttttttteeeeeeeeeeeeed" instead. It even affects the arrow keys.
I am running macOS 12.4 (Monterey) but this happened on 12.3 as well. I have an Apple Magic Keyboard with numeric keypad but from before TouchID. I don't remember exactly when this problem first occurred, but it didn't happen when I originally got my Mac mini four months ago.
Is something wrong with my system installation, or a Bluetooth bug? Please help. Thanks!
Mac mini, macOS 12.4