Map button on form to key on keyboard

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

    Map button on form to key on keyboard

    I have a simple form that I'm using to learn something about HTML and
    JavaScript.

    Can I associate a button on the form with a keyboard key so that when
    the user presses the keyboard key the form thinks the button has been
    clicked?

    Background:
    I'm learning HTML and JavaScript. We did a simple JavaScript that had
    a button that would add the numbers in two input fields.

    I then thought it would be nice to change the form (and the
    JavaScript) to make a "real" calculator.http://fmechess.org/demo/
    calculator.html

    What I would like to do is to make the calculator sensitive to normal
    presses of the keyboard keys, so that instead of clicking on the
    buttons to enter a calcualtion, the user can simply type on the
    keyboard. Is this possible?

    Thanks.

    PS. I hope this is the right ng to ask in, I got "booted" out of the
    HTML ng for asking in there. :)
  • Evertjan.

    #2
    Re: Map button on form to key on keyboard

    MikeB wrote on 10 mei 2008 in comp.lang.javas cript:
    I have a simple form that I'm using to learn something about HTML and
    JavaScript.
    >
    Can I associate a button on the form with a keyboard key so that when
    the user presses the keyboard key the form thinks the button has been
    clicked?
    Yes you can, but not cross browser compatible.
    Background:
    I'm learning HTML and JavaScript.
    Do HTML first, Javascript is another piece of cake.
    We did a simple JavaScript that had
    a button that would add the numbers in two input fields.
    Who is "we", is this a school assignment?
    I then thought it would be nice to change the form (and the
    JavaScript) to make a "real" calculator.http://fmechess.org/demo/
    calculator.html
    Better come with som code that jou are imagining.
    What I would like to do is to make the calculator sensitive to normal
    presses of the keyboard keys, so that instead of clicking on the
    buttons to enter a calcualtion, the user can simply type on the
    keyboard. Is this possible?
    Yes, see above.
    Thanks.
    >
    PS. I hope this is the right ng to ask in, I got "booted" out of the
    HTML ng for asking in there. :)
    Are you sure it was not because you are not showing you did do any
    reseach yourself before you asked?

    Look for HTML 'accesskey' on Google.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • Mervyn Carter

      #3
      Re: Map button on form to key on keyboard

      In article of Sat, 10 May 2008, MikeB writes
      >In Firefox, it doesn't seem to work at all.
      ALT + SHIFT + key works in Firefox

      Anyone found a combination that works in Opera ?

      I have searched their help files to no avail
      --
      Mervyn Carter
      =============== =============== =============== ===
      Note: Spam block in use
      To reply direct you only need one "q" in my eddress
      =============== =============== =============== ===

      Comment

      • Evertjan.

        #4
        Re: Map button on form to key on keyboard

        MikeB wrote on 10 mei 2008 in comp.lang.javas cript:
        You may notice that in that I have mentioned that I have found and
        tried using accesskey and that the results were erratic and
        unpredictable.
        I seem to remember that IE only allows Alt- a to z,
        while IE-mobile [also?] allows Alt- 0 to 9.

        The results however are not erratic and unpredictable,
        they are according to specs of the individual browser.

        The same would apply for FF, Opera, Safari, I suppose.
        Reading the specs before calling something unpredictable.

        The word "Erratic" I would preserve for inconsistent behavour even after
        thorough testing of your programme on each targeted browser. Building for
        cross browser compatibility is a teduous task.

        Errare humanum, debuggere divinum.

        --
        Evertjan.
        The Netherlands.
        (Please change the x'es to dots in my emailaddress)

        Comment

        • Matthias Watermann

          #5
          Re: Map button on form to key on keyboard

          On Sun, 11 May 2008 10:06:30 +0000, Evertjan. wrote:
          MikeB wrote on 10 mei 2008 in comp.lang.javas cript:
          >
          >You may notice that in that I have mentioned that I have found and
          >tried using accesskey and that the results were erratic and
          >unpredictabl e.
          >
          [...]
          The word "Erratic" I would preserve for inconsistent behavour even after
          thorough testing of your programme on each targeted browser. Building for
          cross browser compatibility is a teduous task.
          Unfortunately it's not "just" a (cross-)browser issue. There's something
          else involved: the respective GUI. I stumbled over this problem some years
          ago when some users where quite happy with the pages' access keys while
          others complained that those access keys were misleading and wouldn't
          work. I was able able to find two users with the very same browser, the
          same OS and even the same GUI. However, what was working on one computer
          didn't at the other's. After experimenting and changing the access keys
          we finally figured out what the problem was: The GUI-setup allowed for
          defining hotkeys for whatever purpose (like invoking programs or
          switching desktops). And if such a GUI-based hotkey happens to be the
          same as the one you're using (well, intend to use) on your web-page the
          browser won't even get notified that the key in question was pressed
          let alone have chance to react on it. And because every user is free to
          define her/his favourite hotkeys there's no chance to use a set of
          supposedly unused access keys for your web-page (even if there wouldn't
          be the usual issues with browser incompatibilite s).

          To make a long story short: While access keys are a good idea in theory,
          in practise there's no guarantee whatsoever that they will work anywhere
          (except, may be, the developers own computer).

          --
          Matthias
          /"\
          \ / ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL
          X - AGAINST M$ ATTACHMENTS
          / \

          Comment

          • Evertjan.

            #6
            Re: Map button on form to key on keyboard

            Matthias Watermann wrote on 11 mei 2008 in comp.lang.javas cript:
            On Sun, 11 May 2008 10:06:30 +0000, Evertjan. wrote:
            >
            >MikeB wrote on 10 mei 2008 in comp.lang.javas cript:
            >>
            >>You may notice that in that I have mentioned that I have found and
            >>tried using accesskey and that the results were erratic and
            >>unpredictable .
            >>
            >[...]
            >The word "Erratic" I would preserve for inconsistent behavour even
            >after thorough testing of your programme on each targeted browser.
            >Building for cross browser compatibility is a teduous task.
            >
            Unfortunately it's not "just" a (cross-)browser issue. There's
            something else involved: the respective GUI. I stumbled over this
            problem some years ago when some users where quite happy with the
            pages' access keys while others complained that those access keys were
            misleading and wouldn't work. I was able able to find two users with
            the very same browser, the same OS and even the same GUI. However,
            what was working on one computer didn't at the other's. After
            experimenting and changing the access keys we finally figured out what
            the problem was: The GUI-setup allowed for defining hotkeys for
            whatever purpose (like invoking programs or switching desktops). And
            if such a GUI-based hotkey happens to be the same as the one you're
            using (well, intend to use) on your web-page the browser won't even
            get notified that the key in question was pressed let alone have
            chance to react on it. And because every user is free to define
            her/his favourite hotkeys there's no chance to use a set of supposedly
            unused access keys for your web-page (even if there wouldn't be the
            usual issues with browser incompatibilite s).
            >
            To make a long story short: While access keys are a good idea in
            theory, in practise there's no guarantee whatsoever that they will
            work anywhere (except, may be, the developers own computer).
            Good point, Matthias.

            This leaves us with no other option than not to use the Alt and detect
            the keys by the onkeydown or onkeypress of the page and also of the
            relevant input fields and go from there.

            To the newbee OP: do not follow this advice in your first year.

            --
            Evertjan.
            The Netherlands.
            (Please change the x'es to dots in my emailaddress)

            Comment

            Working...