It’s probably not Godot which is causing that problem but your computer… or lag?
For reference: on my computer that code prints aa... when using my mouse and ab... when using my mouse and keyboard — what you would expect.
Godot like any game engine will try and record all input events every frame, but Godot won’t actually send those events until the frame is rendered (to save performance!), but you can disable that behaviour.
Maybe on your system that’s not working quite right? Try this:
func _ready():
set_use_accumulated_input(false)
Is your system lagging? And do you have a wired mouse you could try out? Can you move the mouse while typing normally?
On second inspection, my touchpad never works when typing, even on non-Godot games. It seems to work with a mouse.