Since the problem is affecting multiple input devices at different times, a good first step is to disconnect all nonessential USB devices, restart the PC, and then test one device at a time. Also check Settings > Accessibility > Keyboard and make sure features such as Sticky Keys, Filter Keys, or Toggle Keys are not causing unexpected behavior, and review Time & language > Typing > Advanced keyboard settings in case the input layout changed unexpectedly. Update hardware drivers through Device Manager and checking Windows Update > Advanced options > Optional updates for device-driver updates.
If the issue continues, the best isolation step is a clean boot, use msconfig, then Hide all Microsoft services, disable the remaining non-Microsoft services, and disable startup apps from Task Manager before restarting. If the random inputs stop in clean boot, re-enable items gradually until you find the culprit.