3 Replies Latest reply on Nov 2, 2007 12:36 PM by BSpero

    Making [enter] work the same as [return]

    SafariTECH Level 1
      If I had the time I would likely be able to figure this out, but I need to continue on other areas to get this project done and hope that maybe someone has figured this out before.

      On our app we have a large text field (scrolling) that is editable and the user enters criteria in it, 1 item per line.

      The problem is that some people like using the enter key [numpad] which places a strange return character in the field and causes the function to fail when they submit the final field. For the meantime I have simply captured the enter key [numpad] and stopped it from entering, BUT what I would like to do is have a script capture the enter key [numpad] and have it enter a proper line return the same way the return key [main keyboard] does.

      So far, any attempts at this in my "on KeyDown" function has failed.

      Can anyone point me in the right direction?

        • 1. Making [enter] work the same as [return]
          BSpero Level 1
          Well, what you could do, instead of having the script that you use to capture the key ignore it, have it insert a RETURN in the text field. So...

          myField.member.text = myField.member.text &RETURN

          Not sure if that is what you're looking for.
          • 2. Making [enter] work the same as [return]
            SafariTECH Level 1
            Thanks for responding ...

            I tried that, thinking it would be a simple solution, but it doesn't put in the line return ... it doesn't seem to do anything though from all appearance.

            • 3. Re: Making [enter] work the same as [return]
              BSpero Level 1
              This code seems to work...

              property spriteNum

              on keyDown
              if the keyCode = 76 then
              sprite(spriteNum).member.text = sprite(spriteNum).member.text & RETURN
              else pass

              Or, I may have realized another issue... If you are using a field instead of a text box, this will not totally work. You will also have to place the cursor on the next line as well. I bet if you try to move the cursor down manually after you press the enter key, you'll see it move down. But, when you just press it, it only adds the carriage return, but doesn't move the mouse to the end of the field. You'll have to add something like...

              on keyUp
              myTextCount = sprite(spriteNum).member.text.char.count
              mem = sprite(spriteNum).member
              the keyboardFocusSprite = spriteNum
              member(mem).selection = [myTextCount,myTextCount]

              What that does is automatically move the cursor to the end of the text. There might be a cleaner way, but that is the general idea.