Skip to main content
Known Participant
October 24, 2013
Question

How can I get keyboard cursor(caret) position in javascript?

  • October 24, 2013
  • 1 reply
  • 3865 views

Hi. I have a question.

How can I get keyboard cursor(caret) position in javascript?

I made a multilined edittext in ScriptUI.

But It's not working about Enter key.

All I want is when I push 'enter' key, begin a new line.

If I know how to get keyboard cursor position, I can insert '\n' character in middle of sentances.

/////////////////////////////////////////////////////////////////////////////////////

var win =new Window ("dialog", '');

          win.orientation = "column";

var grpContents = win.add("group")

          var codeInput = grpContents.add ("edittext", [0, 0, 150, 550], "", {multiline:true});

                    codeInput.alignment = ['fill', 'top']

                    codeInput.active = true;

                   codeInput.onEnterKey = function(){

            codeInput.text = codeInput.text+"\n"

     }

          win.show()

/////////////////////////////////////////////////////////////////////////////////////

I use windowsXP and Illustrator CS3.

If you know about that, please help me!~

This topic has been closed for replies.

1 reply

CarlosCanto
Brainiac
October 24, 2013

All I want is when I push 'enter' key, begin a new line.

press Ctrl+Enter

kimDino8Author
Known Participant
October 25, 2013

Thank you for your reply. I learn one thing because of you.

'Ctrl+Enter' is good and simple. But other person who use my script doesn't know about Ctrl+Enter.

Edittext object have 'onEnterKey' method. So I want to try make 'enter' key working.

If you know about that, please reply for me.

Thank you.

pixxxelschubser
Adobe Expert
October 26, 2013

kimDino8 schrieb:

… 'Ctrl+Enter' is good and simple. But other person who use my script doesn't know about Ctrl+Enter …

Perhaps you try something like this:

var win =new Window ("dialog", '');

win.orientation = "column";

var lineBefore_btn = win.add ("button", undefined, "add new first Line");

var lineAfter_btn = win.add ("button", undefined, "add new last Line");

var grpContents = win.add("group");

var codeInput = grpContents.add ("edittext", [0, 0, 150, 550], "abc\rcdr", {multiline:true});

codeInput.alignment = ['fill', 'top'];

codeInput.active = true;

codeInput.helpTip = "You can also add a new line by clicking [Strg]+[Enter]";

lineBefore_btn.onClick = function () {

    codeInput.text = "\r" + codeInput.text;

    codeInput.active = true;

    }

lineAfter_btn.onClick = function () {

    codeInput.text = codeInput.text + "\r";

    codeInput.active = true;

    }

win.show();