Edit in JSFiddle

function Input(DOMObject){
    var keyMap = [],
        lastKey = 0;
    
    function updateKeys(event){
        keyMap[event.keyCode] = event.type == "keydown";
        lastKey = event.type == "keydown" ? event.keyCode : 0;
        return false;
    }
    
    function pub_keyIsDown(keyID){
        return keyMap[keyID];
    }
    
    function pub_getLastPressed(){
        return lastKey;
    }
    
    DOMObject.onkeydown = DOMObject.onkeyup = updateKeys;
    
    this.keyIsDown = pub_keyIsDown;
    this.getLastPressed = pub_getLastPressed;
}

function mkloop(){
    var el = document.getElementById("txt"),
        input = new Input(el);
    return function(){
        if(input.keyIsDown(0x41)){ // A
            alert("Sorry. Due to some arbitrary rule about pressing A, you are not allowed to press A.");
        } else if (input.keyIsDown(0x11) && input.keyIsDown(0x44)) { // Ctrl+D
            el.value = "";
        } else {
            if(input.getLastPressed()){
                el.value += String.fromCharCode(input.getLastPressed());
            }
        }
    }
}

setInterval(mkloop(), 1000/30);
<textarea id="txt">In this ill-conceived example, I have made a crippled textarea.
Press A if you can.
Press Ctrl+D to wipe text.
Anything else will result in garbage being printed.</textarea>
textarea{
    width:100%;
    height:500px;
}