Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Detect which edittext is activated

Tagged: 

  • Detect which edittext is activated

    Posted by Rodrigo Aben on September 9, 2020 at 4:36 am

    I’m using Peter Kahrel’s guide to dinamically create an UI and I want to fill the selected edittext with a keyboard entry. Since all edittexts are created on the fly, how do I check which one is selected? My function works fine on the first one but not on the next field. I accidently marked this as basic, sorry.


    var win = new Window ("dialog");
    var maingroup = win.add ("panel {orientation: 'column'}");
    add_row (maingroup);
    var show_btn = win.add ("button", undefined, "Save presets");
    show_btn.onClick = function () {
    var txt = "";
    for (var n = 0; n < maingroup.children.length; n++) {
    txt += maingroup.children[n].edit.text + "\n";
    }
    alert ("Rows: \n" + txt);
    }
    win.show ();
    function add_row (maingroup) {
    var group = maingroup.add ("group");
    group.statictext = group.add ("statictext", undefined, "Left-click +");
    group.edit = group.add ("edittext", ["", "", 200, 20], "Click here and press any key");
    group.plus = group.add ("button", undefined, "+");
    group.plus.onClick = add_btn;
    group.minus = group.add ("button", undefined, "-");
    group.minus.onClick = minus_btn;
    group.index = maingroup.children.length - 1;
    group.edit.onActivate = function(){
    win.addEventListener ("keydown", function (kd) {pressed (kd)});
    function pressed (k) {
    if(k.keyName === "Enter"){
    group.edit.text = "Enter";
    }
    }
    }
    win.layout.layout (true);
    }
    function add_btn () {
    add_row (maingroup);
    }
    function minus_btn () {
    maingroup.remove (this.parent);
    win.layout.layout (true);
    }
    Rodrigo Aben replied 5 years, 8 months ago 1 Member · 2 Replies
  • 2 Replies
  • Rodrigo Aben

    September 10, 2020 at 6:41 pm

    Solved! Logical problem actually. I was adding the event listener to the window and not to the actual group. This is the proper way to write it:

    var win = new Window ("dialog");
    var maingroup = win.add ("panel {orientation: 'column'}");
    add_row (maingroup);
    var show_btn = win.add ("button", undefined, "Save presets");
    show_btn.onClick = function () {
    var txt = "";
    for (var n = 0; n < maingroup.children.length; n++) {
    txt += maingroup.children[n].edit.text + "\n";
    }
    alert ("Rows: \n" + txt);
    }
    win.show ();
    function add_row (maingroup) {
    var group = maingroup.add ("group");
    group.statictext = group.add ("statictext", undefined, "Left-click +");
    group.edit = group.add ("edittext", ["", "", 200, 20], "Click here and press any key");
    group.plus = group.add ("button", undefined, "+");
    group.plus.onClick = add_btn;
    group.minus = group.add ("button", undefined, "-");
    group.minus.onClick = minus_btn;
    group.index = maingroup.children.length - 1;
    group.addEventListener ("keydown", function (kd) {pressed (kd)});
    function pressed (k) {
    if(k.keyName === "Enter"){
    group.edit.text = "Enter";
    }
    }

    win.layout.layout (true);
    }
    function add_btn () {
    add_row (maingroup);
    }
    function minus_btn () {
    maingroup.remove (this.parent);
    win.layout.layout (true);
    }
  • Rodrigo Aben

    September 10, 2020 at 6:42 pm

    BTW, I keep having no ideia of how .onActivate() works. Tryied different things but none of them returns anything.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy