It's not that "[Return] makes the page refresh"; It's that some (many?) browsers, by default, will treat a [Return] in text inputs as a sign of form submit-ion.
And that seems to happen on key down, so preventing this upon key up is, too late.
Add an extra listener to
onkeydown may help:
<input onkeydown="preventSubmit(event);" onkeyup="keyPressCodeTitle(event);" />