Keyboard misbehavior triggered by...?

Check out these troubleshooting steps provided by @Tom.

If all else fails, and it is important to you to make things work correctly, you may need to do a clean install of the macOS, and then be very careful and selective about what stuff you install.