Key interrupts

Discussion in 'Javascript' started by Simon Wigzell, Mar 8, 2005.

  1. I would like to interrupt particular key strokes on a webpage, e.g. CTRL S
    and have a javascript function called much like I can do this:

    <body onclick="alert('Hello World')">

    Only it would be triggered by CTRL S and calls a function of mine.
    What would be the syntax? for this? Thanks.
     
    Simon Wigzell, Mar 8, 2005
    #1
    1. Advertising

  2. Simon Wigzell

    juglesh Guest

    "Simon Wigzell" <> wrote in message
    news:uUlXd.609711$Xk.154555@pd7tw3no...
    >I would like to interrupt particular key strokes on a webpage, e.g. CTRL S
    >and have a javascript function called much like I can do this:
    >
    > <body onclick="alert('Hello World')">
    >
    > Only it would be triggered by CTRL S and calls a function of mine.
    > What would be the syntax? for this? Thanks.


    <
    http://groups-beta.google.com/group...7b52c26?q=onKeyPress juglesh#f90ec21127b52c26 >

    CTRL wont work, afaik, but shift will:
    http://www.js-examples.com/syntax/key_codes.php

    --
    juglesh
     
    juglesh, Mar 8, 2005
    #2
    1. Advertising

  3. Simon Wigzell

    Guest

    To start with you will have to write an event handler for the
    onKeyDown/onKeyUp/onKeyPress event. Choosing which depends on what all
    controls you have in the page.
    You could do this for the entire body of the page by having an
    onKeyPress="javascript:myEventHandler()"
    attribute in the <body> tag.
    Inside the myEventHandler() function, you could check for the
    event.keyCode variable to check for the key pressed. You could also use
    event.ctrlKey and event.shiftKey to check the state of the ctrl, shift
    keys. They are booleans.
    juglesh, wont event.ctrlKey work?
    I had a requirement of disabling ctrl+n in one of my apps, and i was
    able to do it.

    Thanks

    Anand
     
    , Mar 9, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. D.Sn

    Interrupts in VB (API)

    D.Sn, Jan 12, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,770
    Willy Denoyette [MVP]
    Jan 12, 2004
  2. Ciaran
    Replies:
    12
    Views:
    6,104
    Frank van Eijkelenburg
    Feb 27, 2004
  3. guru10
    Replies:
    1
    Views:
    1,237
  4. Victor Bazarov

    Keyboard interrupts

    Victor Bazarov, Mar 28, 2005, in forum: C++
    Replies:
    8
    Views:
    8,787
    Ioannis Vranos
    Mar 29, 2005
  5. M P
    Replies:
    1
    Views:
    505
Loading...

Share This Page