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:
Is your system lagging? And do you have a wired mouse you could try out? Can you move the mouse while typing normally?