Does this occur whenever the keyboard is open or in specific apps? Are you using any 3rd party keyboards or the Samsung Keyboard? I would recommend testing the device in safe mode to see if your symptoms persist. You can do so by following these steps.
Press and hold the power button until power off, restart, and emergency mode show on the screen
Tap and hold on the power off option until it changes to safe mode, then tap on safe mode
The phone will then reboot into safe mode. You will be able to check that it is by a grey transparent box in the bottom left of the screen that says safe mode.
If you are still experiencing this I would recommend resetting your Samsung keyboard. You can do so by going to Settings>General Management>Language and Input>On-screen Keyboard>Samsung Keyboard>Reset to default settings.
Let me know if this helps!