(Esc while Space is held doesn’t cancel, but Tab does.)
You’re only answering half of the inconsistency: because Enter activates buttons like any other key, on keydown.
Just diving in without full context, but, enter is often a completion action. Historically often a full carriage return. It often means "submit data".
So this could be the oddity
While spacebar is depressed:
Qt: Esc cancels. Tab cancels.
Gtk-4: Spacebar auto-clicks before keyup (probably due to auto-repeat).
Win32: Esc sends Esc to the window. Tab cancels.
Firefox: Esc does nothing. Tab cancels.
So, mileage does vary.
Re. Enter key, that's a different key, so different discussion.