Well, if your problem is translation of the keycodes to characters, why not let the browser handle it for you? This might sound hideous, but you could simply allow the browser modify the text box (so that delete is a delete, and a period is a period), and then go back and edit it... Um... maybe something like this:
function hookEvents() {
$('#myTextBox').oldValue = $('#myTextBox').value;
$('#myTextBox').bind('keyup', function(event) {
// Maybe nothing's changed?
if (event.target.oldValue == event.target.value) {
return;
}
var validInput = /(\-?[0-9]*(?:\.[0-9]*)?)/;
var input = event.target.value;
var result = validInput.exec(input);
if (result.index != 0 || result[result.length-1] != input.length)
{
event.target.value = result[0];
}
// update for later
event.target.oldValue = event.target.value;
});
}
The biggest problem with this approach is that every key pressed appears on screen for a moment. On the other hand, with the REGEX you have a lot more control over the format of the allowed input. In the example above, I only allow positive or negative numbers (with an optional decimal point). Such as: "123", "-123", "-123.456", "123.456".
I know this doesn't really answer your question, but it sidesteps the issue entirely!