Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Adding a keyboard listener to script window

  • Adding a keyboard listener to script window

    Posted by Jacob Roth on November 14, 2019 at 6:28 pm

    Hello all,

    I’m trying to write a script that will let me parent layers with nothing but the keyboard. I’ve gotten to the point where the script can change the parent of a layer, but I can’t get the script to execute without clicking a button.

    I’ve read that event listeners no longer work in ExtendScripts. Is there another way to add a keyboard command onto a UI button?

    var mainComp = app.project.activeItem;
    var mainWindow = new Window("palette","The Parenter", undefined);

    var groupOne = mainWindow.add("group", undefined,"groupOne");
    groupOne.orientation = "column";

    groupOne.add("statictext", undefined,"This script Parents your layers");
    var theParent = groupOne.add("edittext", undefined, "Parent");
    var firstChild = groupOne.add("edittext", undefined, "First Child");

    var groupTwo = mainWindow.add("group", undefined, "Buttons");
    groupTwo.orientation = "row";
    var startButton = groupTwo.add("button", undefined, "Parent!");
    var cancelButton = groupTwo.add("button", undefined, "Cancel")

    startButton.onClick = function(){
    app.beginUndoGroup("Parent");
    doThings();
    }
    cancelButton.onClick = function(){
    mainWindow.close();
    }

    function doThings(){
    var setParent = parseInt(theParent.text);
    var setChildren = parseInt(firstChild.text);
    mainComp.layer(firstChild).parent = mainComp.layer(setParent);

    mainWindow.close();
    app.endUndoGroup("Parent");
    }

    mainWindow.show();
    mainWindow.center();

    Jacob Roth replied 6 years, 8 months ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

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