Skip to main content
The_Kitty
Inspiring
September 21, 2022
Answered

Ctrl,Alt onClick Button in script

  • September 21, 2022
  • 2 replies
  • 283 views

I want to use Alt Click for 1 button but using onAltClick.function() is not working

Can anyone help me, thanks a lot !

This topic has been closed for replies.
Correct answer Dan Ebberts

Play around with this:

var myDlg = new Window("dialog");
var button = myDlg.add("button", undefined, "TEST");

button.onClick = function() {
	if ( ScriptUI.environment.keyboardState.altKey ) {
		alert("Alt + button click");
	}else if ( ScriptUI.environment.keyboardState.ctrlKey ) {
		alert("Ctrl + button click");
	}else{
		alert("button click");
	}
}

myDlg.show();

2 replies

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
September 21, 2022

Play around with this:

var myDlg = new Window("dialog");
var button = myDlg.add("button", undefined, "TEST");

button.onClick = function() {
	if ( ScriptUI.environment.keyboardState.altKey ) {
		alert("Alt + button click");
	}else if ( ScriptUI.environment.keyboardState.ctrlKey ) {
		alert("Ctrl + button click");
	}else{
		alert("button click");
	}
}

myDlg.show();
Mylenium
Legend
September 21, 2022

You will have to explicitly remap such functions by defining the inbut keys. They're not predefined. Generally, though, it's not a good idea to hide multiple functions behind buttons in scripts. Simply create a separate button.

 

Mylenium