Buttons Fire From Random Keyboard Input

I have a QR code scanner that acts as a keyboard emulator that parts of my app use. When used it passes a string GUID and a carriage return. I have noticed that when nothing in particular seems to be in focus and this scanner is used I will get seemingly random click events on buttons all over my project. My best theory currently is that some element I am unaware of, some button, somehow still has or got focus and the carriage return is causing the button to get pressed. When I looked in the button class, however, it seems to only listen to Left Mouse, so I am not sure why this is. Also no amount of fiddling with .Focus() and .Blur() effects has been able to fix this issue.

Advice? High level, how do I prevent random rapid keyboard mashing (or in my case a scanner) from triggering buttons that were not mouse-pressed?

Also I marked this as “bug” as it may be one. Are buttons meant to take keyboard returns as “clicked” events?

This is probably due to the default input mapping for UI. Some of these I know include the WSAD keys for button navigation. Fortunately the input system can be fully customized:

https://docs.unity3d.com/Packages/com.unity.inputsystem@1.4/manual/UISupport.html#setting-up-ui-input

Oooo great tip, I will try it out. I suspected the same.