Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
I achieved thru scriptUI object only after button click thru CSinterface. I thought it would not work without even trying and was finding other ways.But, eventually the one which is already there is working fine. Thanks for enlightenment.