The keyup
event returns a keycode not an ASCII
code. If you switch to the keypress
event you can retreive the ASCII
code. This should match the value received by charCodeAt
which returns the unicode value of a character, which happens to align with the ASCII
code for the first 128 characters. See this reference.
var delimiter = ',';
var key = delimiter.charCodeAt(0);
document.getElementById("test").onkeypress = function(e){
if((e.keyCode || e.which) == key){
alert("Cat's out of the bag! OHHH YEAH!");
}
};