Key interrupts

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Wigzell

    #1

    Key interrupts

    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.


  • juglesh

    #2
    Re: Key interrupts


    "Simon Wigzell" <simonwigzell@s haw.ca> wrote in message
    news:uUlXd.6097 11$Xk.154555@pd 7tw3no...[color=blue]
    >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.[/color]

    <
    http://groups-beta.google.com/group/...0ec21127b52c26 >

    CTRL wont work, afaik, but shift will:


    --
    juglesh


    Comment

    • c.anandkumar@gmail.com

      #3
      Re: Key interrupts

      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="jav ascript:myEvent Handler()"
      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

      Comment

      Working...