Skip to main content
Inspiring
November 6, 2021
Question

AE Extension | Trigger 9 different functions with single button and keyboard Numpad 1-9

  • November 6, 2021
  • 1 reply
  • 204 views

I want 9 different functions to be triggered by single button and keyboard numpad (1-9) in my After effects extension. I got some solution from stackoverflow and it works fine in online html editors but doesn't work in after effects. Below is the sample code. Can someone plz help.

<button type="button" id="b41" onclick="myFunction(event)">myButton</button>
<script>
const pressedButtons = {};

window.onkeydown = (e) => (pressedButtons[e.which] = true);
window.onkeyup = (e) => (pressedButtons[e.which] = false);

function myFunction(event) {

if (pressedButtons[97]) {
setOpacity_0();
} else if (pressedButtons[98]) {
setOpacity_100();
} else {
setOpacity_50();
}
}
</script>

This topic has been closed for replies.

1 reply

Mylenium
Legend
November 6, 2021

I'm not clear what you are asking. Your code does not contain any event listener that actually intercepts the key commands nor can I see anything pertaining to your functions/ button definitions. I suggest you actually look it up in the AE scripting docs or refer to useful tutorials like this:

 

https://www.youtube.com/watch?v=UBqdWdDmvao

 

Mylenium

Inspiring
November 6, 2021

This am not trying to achieve using  scriptUI.environment in jsx.

 

This am trying to get key pressed on cep panel button..

 

Functions ll be triggered using csinterface which I didn't mention in question.. Now am mentioning below.

 

<button type="button" id="b41" onclick="myFunction(event)">myButton</button>
<script>
const pressedButtons = {};

window.onkeydown = (e) => (pressedButtons[e.which] = true);
window.onkeyup = (e) => (pressedButtons[e.which] = false);

function myFunction(event) {

if (pressedButtons[97]) {
CSinterface.evalScript("setOpacity_0()");
} else if (pressedButtons[98]) {
CSinterface.evalScript("setOpacity_100()");
} else {
 CSinterface.evalScript(" setOpacity_50()");
}
}
</script>

 

Excuse me if any typo errors while typing the code. "setOpacity_50()" function just sets opacity of layer to 50 and this function in included in jsx script and it runs fine.. I don't have any prob in scripting. 

 

What I do is,I ll hold numpad1 and click the above button then it ll trigger function 1, and I hold numpad2 and click the above button then it ll trigger function 2.

 

.Hope u understand my concern now.. 

I didn't try with scriptUI.environment using cep panel and csinterface, let me  check anyways.  Thank you