3 Replies Latest reply on Jan 9, 2009 4:44 PM by Newsgroup_User

    Enter,Return key causing user input issues PLEASE HELP

    sarah louise water
      Hi
      Can anyone please advise me about restricting the keyboard keys so that they do not cause a small single line field to create a new line and alerting the user to use the button?

      I have used the code triggered by a button press.

      if the key = enter then
      performSearch ------- database search using user input
      end if

      I have also tried messing with the properties of the field with no success.

      Can anyone help please?

      Merry Christmas
      Many Thanks
      Sarah
        • 1. Re: Enter,Return key causing user input issues PLEASE HELP
          Level 7
          Attach this code to the field

          on keyDown me
          if the key = ENTER or the key = RETURN then
          alert("Please use the button")
          else
          pass
          end if
          end


          sarah louise water wrote:
          > Hi
          > Can anyone please advise me about restricting the keyboard keys so that they
          > do not cause a small single line field to create a new line and alerting the
          > user to use the button?
          >
          > I have used the code triggered by a button press.
          >
          > if the key = enter then
          > performSearch ------- database search using user input
          > end if
          >
          > I have also tried messing with the properties of the field with no success.
          >
          > Can anyone help please?
          >
          > Merry Christmas
          > Many Thanks
          > Sarah
          >
          >
          • 2. Re: Enter,Return key causing user input issues PLEASE HELP
            James Newton, ACP Level 3
            Here's a behavior to attach to the button sprite. If the user presses the Return or the Enter key, the button will behave as if it had been clicked. You will need a second behavior on the same button sprite to determine what happens on mouseUp.


            • 3. Re: Enter,Return key causing user input issues PLEASE HELP
              Level 7
              Simpler code to do the same thing (but put it on the field receiving the
              text, rather than the button):

              on keyDown
              case the key of
              RETURN, ENTER: sprite("Button').mouseUp()
              otherwise: pass
              end case
              end

              Though you might want to add in some other cases for other keys you want to
              disallow or give special treatment to in the text field, e.g. Tab,
              Backspace, arrows, etc., depending on your needs. You can also use this
              method to limit the number of chars in the field, which can prevent the text
              from wrapping on its own, like so:

              on keyDown
              case the key of
              "a","b","c", ... "x","y","z": if member("TextMember").char.count < 50
              then pass
              RETURN, ENTER: sprite("Button').mouseUp()
              end case
              end

              Filling in the rest of the letters I skipped, of course, and whatever other
              characters you want to allow.