title: Javascript Replace KeyPress on Input
body: <p><strong>So I was trying replace the key press "K" with "Z" in an input field.</strong>
  <strong>I was successfully able to do it</strong>. <strong>But there is a slight delay which makes the user see that the "K" being changed to "Z".</strong> </p>
  
  <p>This is my code:</p>
  
  <pre><code>        function prinner (event)
          {
            document.getElementById("txx").innerHTML= event.key; //Displays key pressed on screen by changing text element.
             if(event.keyCode == 32){
                 // User has pressed space
                 document.getElementById("txx").innerHTML= "Space";
             }
             if (event.key=="k") // Trying to replace this with z.
             {
              var curval = $("#namaye").val(); //namaye is the ID of the input field.
              var nval = curval.slice(0,(curval.length-1))+"z";
              $("#namaye").val(nval);
  
             }
          }
  
         $("#namaye").keyup(prinner);
  </code></pre>
  
  <p>Does anyone know a better way to achieve this without the delay?</p>