Skip to main content
gregreser
Legend
May 2, 2016 5:34 PM UTC
Answered

Bridge CC edittext keydown event not working

As of Bridge 6.2.0.179 x64, the event listeners 'keydown' and 'keyup' still do not work. I think the mouse events are also broken.

What I'm trying to do:

Create a search box that executes the search when the user presses the "Enter" key.  Pretty standard, but as of yet, impossible in Bridge CC.

I am currently using a "Go" button to execute the search, but users are requesting the "Enter" key functionality.

These two functions work in CS6, but not CC:

editText2.addEventListener ("keydown", function (k){

    if (k.keyName == "Enter"){

            alert("Enter key pressed")

            }

    })

editText2.addEventListener ('keydown', function (e){

    if(ScriptUI.environment.keyboardState.keyName == "Enter"){

        getWebVocab()

        }

    }

Given Adobe's lack of response to other CC ScriptUI bugs, I don't have much faith that this problem will be fixed. Bridge: ExtendScript UI not drawing correctly | Photoshop Family Customer Community

Does anyone have a workaround?

This topic is closed to new replies. Start a new post to keep the conversation going.
Pedro Cortez Marques
Pedro Cortez MarquesCorrect answer
Legend
May 20, 2016 11:39 AM UTC

Hi

On Bridge, the ScriptUI.environment.keyboardState.keyName doesn't work. It returns undefined.

Instead, on UI edittext, there are 2 native functions you can call:

onChanging > triggers ech time you insert/delete a key or paste/delete a string from clipboard

onChange > triggers when you loose focus clicking outside the edittext or ENTERing the text

I also invent a ways of retrieving that last Key entered using the function findMyEnter.

This retrieves nothing when deleting but retrieves a single Key when you are inserting text anywhere, or retrieves a full string pasted inside the edittext

If you run this on Bridge, the results can be seen on the status bar (Bridge window, under on the left). I hope it helps!

var w = new Window('dialog');

var editText = w.add ("edittext", undefined, "");

editText.size = [200,18];

editText.text = "";

var lastText = editText.text;

editText.onChanging = function () {

    var KEYS = [ScriptUI.environment.keyboardState.keyName, ScriptUI.environment.keyboardState.ctrlKey, ScriptUI.environment.keyboardState.shiftKey, ScriptUI.environment.keyboardState.altKey];

    app.document.status = "keyName: " + KEYS[0] +" | ctrlKey: " + KEYS[1] +" | shiftKey: " + KEYS[2] +" | altKey: " + KEYS[3] + " >> Last key entered: " + findMyEnter(lastText, this.text);

    lastText = this.text;

}

editText.onChange = function () {

    app.document.status = "Text Entered: " + this.text;

}

w.show();

function findMyEnter (a,b) { // a:before | b:after

    for (var i=0; i<=a.length ; i++) {

        var A = b.match(new RegExp(a.substr (0, i) + "(.+?)" + a.substr (i, a.length-i)));

        if (A != null) {

            return A[1];

        } else {

            if (a.length == i) return "";

        }

    }

}

2 replies

Pedro Cortez Marques
Pedro Cortez MarquesCorrect answer
Legend
May 20, 2016 11:39 AM UTC

Hi

On Bridge, the ScriptUI.environment.keyboardState.keyName doesn't work. It returns undefined.

Instead, on UI edittext, there are 2 native functions you can call:

onChanging > triggers ech time you insert/delete a key or paste/delete a string from clipboard

onChange > triggers when you loose focus clicking outside the edittext or ENTERing the text

I also invent a ways of retrieving that last Key entered using the function findMyEnter.

This retrieves nothing when deleting but retrieves a single Key when you are inserting text anywhere, or retrieves a full string pasted inside the edittext

If you run this on Bridge, the results can be seen on the status bar (Bridge window, under on the left). I hope it helps!

var w = new Window('dialog');

var editText = w.add ("edittext", undefined, "");

editText.size = [200,18];

editText.text = "";

var lastText = editText.text;

editText.onChanging = function () {

    var KEYS = [ScriptUI.environment.keyboardState.keyName, ScriptUI.environment.keyboardState.ctrlKey, ScriptUI.environment.keyboardState.shiftKey, ScriptUI.environment.keyboardState.altKey];

    app.document.status = "keyName: " + KEYS[0] +" | ctrlKey: " + KEYS[1] +" | shiftKey: " + KEYS[2] +" | altKey: " + KEYS[3] + " >> Last key entered: " + findMyEnter(lastText, this.text);

    lastText = this.text;

}

editText.onChange = function () {

    app.document.status = "Text Entered: " + this.text;

}

w.show();

function findMyEnter (a,b) { // a:before | b:after

    for (var i=0; i<=a.length ; i++) {

        var A = b.match(new RegExp(a.substr (0, i) + "(.+?)" + a.substr (i, a.length-i)));

        if (A != null) {

            return A[1];

        } else {

            if (a.length == i) return "";

        }

    }

}

Translate
gregreser
gregreserAuthor
Legend
May 22, 2016 6:46 PM UTC

Thanks, Pedro, this works!  Monitoring the last key pressed can be very useful, so it's good to see how it is done.

Your answer made me revisit why I didn't use onChange and then I remembered it was causing my function to run twice. Looking more closely at the documentation, I found the solution was to add the creation property enterKeySignalsOnChange to the editText object.

editText = window.add('edittext', undefined, "",{enterKeySignalsOnChange:true});

editText.onChange = function(){ 

    myFunction();

    }

Translate