how do i trap key press events

Results 1 to 6 of 6

Thread: how do i trap key press events

  1. #1
    indu Guest

    Default how do i trap key press events

    How to detect combination of key presses? i wanna track down ctrl N and ctrl M.<BR><BR>thanks<BR>

  2. #2
    Nilesh S. Guest

    Default RE: how do i trap key press events

    Hi indu ,<BR>you can write a small javascript code in order to detect the keypress event and use window.Event.keycode to get the ASCII value of the key pressed...<BR><BR>Regards<BR>Nilesh<BR>

  3. #3
    indu Guest

    Default thanx, not possible with asp?

    thanks for the hint. is it not possible to do this from asp with vbscript?<BR><BR>

  4. #4
    Vijay Guest

    Default RE: thanx, not possible with asp?

    You must understand first that the ASP script is executed at the server. your server processes the .asp file & sends the HTML page to the browser. <BR>After this the connection with the server is disconnected. <BR><BR>And when the user presses any key on his keyboard, your ASP script will have no idea about it. <BR><BR>So you need only client side scripting to capture the key events.<BR><BR>OK, one more point....<BR><BR>event.keyCode works in IE. <BR><BR>For NS4.x , you need to capture event.which.<BR><BR>So detect the browser & then kayStrokes.<BR><BR>Best luck..<BR>

  5. #5
    indu Guest

    Default thank u - how do i run this code

    hi,<BR><BR>thanks a lot. i got the code for this on the web. i am a total newbie to asp. i am doing some testing and debugging. can u just tell me the missing parts of this code to make it run?<BR><BR>ns4=(document.layers)?true:false<BR>ie 4=(document.layers)?true:false<BR><BR>function KeyDown(e){<BR> if (ns4) {var nKey = e.which; var ieKey = 0}<BR> if (ie4) {var ieKey = event.keyCode; var nKey = 0}<BR> alert("nKey:"+nKey+"ieKey:"+ieKey)<BR> if ((ieKey==13) &#124&#124 (nKey == 13))<BR> {<BR>alert(&#039;Operation not allowed&#039;);<BR> }<BR>}<BR><BR>document.onkeydown = keyDown<BR>if (ns4) document.captureEvents(Event.KEYDOWN)<BR><BR>can anyone help with this?

  6. #6
    vijay Guest

    Default RE: thank u - how do i run this code

    The code is perfect.<BR><BR>Just press the keys, you want to detect. A alert message will pop-up. Note the value of the nKey: ...<BR><BR>in the next if if statement, replace the nKey== , with the value of nKey. <BR><BR>then do whatever you want.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts