Page 1 of 1

onAltClick or onControlClick

Posted: November 19th, 2013, 4:32 am
by bkan
Hello,
How do you write this event "onAltClick" or "onControlClick"? I know it's possible, I saw this on other scripts. Any idea?

Re: onAltClick or onControlClick

Posted: November 19th, 2013, 7:40 am
by beginUndoGroup

Code: Select all

function onTestButtonClick(ev)
{
	var b = ev.target;
	if (!(b instanceof Button)) return;
	
	var modState = ScriptUI.environment.keyboardState;
	
	if (modState.shiftKey) alert('nicely shifted !')
	else if (modState.altKey) alert('Alt+Click not supported !!!')
	else alert("You just plain-pressed a plain button.");
	};


var pal = new Window("palette", "test", undefined, {resizeable: true});
pal.content = pal.add("group{alignment: ['left', 'top'], btn: Button{text:'test', size: [60,20]}}");
pal.content.btn.addEventListener('click', onTestButtonClick);
pal.center(); pal.show();
more info in the Javascript Tool Guide, or in this very nice pdf: http://www.kahrel.plus.com/indesign/scriptui.html

Re: onAltClick or onControlClick

Posted: November 20th, 2013, 7:13 am
by bkan
Oh, thank you, it works like a charm!! Thank you!!

Re: onAltClick or onControlClick

Posted: November 20th, 2013, 7:18 am
by bkan
Just something else : is it possible to detect when the user is only pressing "shift" (and not "click + shift")? I just would want to change the name of the button when the user press shift on it : is it possible?
Thanks!!

Re: onAltClick or onControlClick

Posted: November 21st, 2013, 1:47 am
by beginUndoGroup
i dont know how to do that.

The thing is that if you use a mouse event handler, the shiftKey should be pressed BEFORE the mouse enters the button region, and it is not quite what a user expects.
There is an event type for the mouse entering the button's region ('mouseover'), leaving the button's region ('mouseout'), moving above the button's region ('mousemove'), but nothing for staying idle over the button: it is not an event, just a state.

So the event should be a keyboard event (the shiftKey is pressed) and upon that event determine if the key is above the button: no idea how to do that.
There is a KeyboardEvent object (never used), but how to read the mouse state afterwards, still no idea.

If there is a solution to that, you should find it in the Javascript Tool Guide > Event Handling, and if you find it, please come back and post ;)

Xavier.