onkeypress event: ' and / characters

Discussion in 'Javascript' started by cloudguitar, Feb 10, 2008.

  1. cloudguitar

    cloudguitar Guest

    Hello all!

    In some engines like Gecko(Firefox) and KHTML(Konqueror), pressing the
    ' or / key
    turns the "quick find" mode on in the browser, moving the focus away
    from the current element.

    I have a webpage with document.onkeypress set to a callback function,
    and I'd like to
    be able to work with all the key events without losing the focus. Is
    there any workaround that
    would me let disable that "quick find" mode from JS or, anyway, avoid
    losing the focus?

    Thank you very much,

    Claudio A.
     
    cloudguitar, Feb 10, 2008
    #1
    1. Advertisements

  2. return false; from the handler will block more or less any key action.

    Joost.
     
    Joost Diepenmaat, Feb 10, 2008
    #2
    1. Advertisements

  3. cloudguitar

    SAM Guest

    cloudguitar a écrit :
    that doesn't append when you type in a text-field
    and of corse you absolutly need to use these 2 keys ? !
     
    SAM, Feb 10, 2008
    #3
  4. cloudguitar

    cloudguitar Guest

    I think I found a decent solution, even if it's a trick and not a
    "canonical" one.

    I put a <input id="in" style="width:0; height:0" readonly></input>
    inside the page.
    Then, I use its onkeypress to retrieve the keys, and that does work
    very well, as
    no browser-specific shortcut is active on INPUT fields.
    Again, to avoid losing the focus from the INPUT, I put a handler to
    document.getElementById("in").onblur and to document.onfocus that sets
    the focus back
    to the INPUT field. It seems to work even on Explorer 6.

    I needed those two uncommon keys because I listen to _code_ input, and
    it would be a
    significant reduction not to include them.

    Thanks for your suggestions

    Claudio A.
     
    cloudguitar, Feb 10, 2008
    #4
  5. cloudguitar

    cloudguitar Guest

    I think I found a decent solution, even if it's a trick and not a
    "canonical" one.

    I put a <input id="in" style="width:0; height:0" readonly></input>
    inside the page.
    Then, I use its onkeypress to retrieve the keys, and that does work
    very well, as
    no browser-specific shortcut is active on INPUT fields.
    Again, to avoid losing the focus from the INPUT, I put a handler to
    document.getElementById("in").onblur and to document.onfocus that sets
    the focus back
    to the INPUT field. It seems to work even on Explorer 6.

    I needed those two uncommon keys because I listen to _code_ input, and
    it would be a
    significant reduction not to include them.

    Thanks for your suggestions

    Claudio A.
     
    cloudguitar, Feb 10, 2008
    #5
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.