Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

addEventListener click Problem

New Here ,
Dec 23, 2019 Dec 23, 2019

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
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 23, 2019 Dec 23, 2019

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 01, 2020 May 01, 2020

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?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 07, 2020 May 07, 2020
LATEST

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
};

 

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