Highlighted

addEventListener click Problem

New Here ,
Dec 23, 2019

Copy link to clipboard

Copied

I test Mouse Events and its work Perfectly (Left, Right, Middle KEYS) at Extend Script

 

But when run it on Aftereffects 2018 the left-key in mouse doesn't do anything

 

var w = new Window("palette"); 
var b = w.add ("button", [0,0,150,50], "test");


    w.center();
    w.show();  
    
    

    b.addEventListener ('click', function(K){
        var keys = [];
        if (K.ctrlKey) {
            keys[0] = "CTRL";
            }
        if (K.shiftKey) {
            keys[1] = "SHIFT";
            }
        if (K.altKey) {
            keys[2] = "ALT";
            }
        alert(K.button + "\n" + keys.toString() + "\n" + K.clientX + "    |   " + K.clientY);
        }
    )

 

TOPICS
Error or problem, Scripting

Views

366

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

addEventListener click Problem

New Here ,
Dec 23, 2019

Copy link to clipboard

Copied

I test Mouse Events and its work Perfectly (Left, Right, Middle KEYS) at Extend Script

 

But when run it on Aftereffects 2018 the left-key in mouse doesn't do anything

 

var w = new Window("palette"); 
var b = w.add ("button", [0,0,150,50], "test");


    w.center();
    w.show();  
    
    

    b.addEventListener ('click', function(K){
        var keys = [];
        if (K.ctrlKey) {
            keys[0] = "CTRL";
            }
        if (K.shiftKey) {
            keys[1] = "SHIFT";
            }
        if (K.altKey) {
            keys[2] = "ALT";
            }
        alert(K.button + "\n" + keys.toString() + "\n" + K.clientX + "    |   " + K.clientY);
        }
    )

 

TOPICS
Error or problem, Scripting

Views

367

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 23, 2019 0
New Here ,
Dec 23, 2019

Copy link to clipboard

Copied

I fix the problem in this way :

    var ctrl = false;
    var shift = false;
    var alt = false;


    b1.onClick = function() {  
        
         if(ctrl){
             alert("CTRL");
             }
         if(shift){
             alert("SHIFT");
             }
         if(alt){
             alert("ALT");
             }
         if(!ctrl && !shift && !alt) {
             alert("NO KEY");
             }

         ctrl = false;
         shift = false;
         alt = false;
    }
    
    b1.addEventListener ('mousedown', function(K){
    
        if (K.ctrlKey) {
            ctrl = true;
            }
        if (K.shiftKey) {
            shift = true;
            }
        if (K.altKey) {
            alt = true;
            }
    })

 

If anybody has a better solution please put it here

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 23, 2019 0
Explorer ,
May 01, 2020

Copy link to clipboard

Copied

Wow, thx so much for the solution.

 

I have the same problem, tried erverything I can but still didn't find a good solution until now.

 

Before this, if I want to do the alt-click/shift-click stuff, I have to replace my buttons with images. But doing so, I have to do the highlighting manually while my mouse is on the image.  This is very fraustrating to work with. Your solution is great!

 

And can @Adobe fix this nasty bug so everybody can develope scripts better?

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 01, 2020 0
Adobe Community Professional ,
May 07, 2020

Copy link to clipboard

Copied

There's a perfectly logical way to catch modifier keys by checking ScriptUI.environment.keyboardState: http://estk.aenhancers.com/4%20-%20User-Interface%20Tools/event-handling.html?highlight=keyboardstat...

Here's the gist of it:

button.onClick = function() {
	var keyboardState = ScriptUI.environment.keyboardState;
	if (keyboardState.shift) {
		alert('shift');
	}

	// etc
};

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 07, 2020 0