onAltClick or onControlClick

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
bkan
Posts: 51
Joined: November 6th, 2013, 8:33 am

Hello,
How do you write this event "onAltClick" or "onControlClick"? I know it's possible, I saw this on other scripts. Any idea?
beginUndoGroup
Posts: 81
Joined: November 27th, 2012, 6:41 am

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
bkan
Posts: 51
Joined: November 6th, 2013, 8:33 am

Oh, thank you, it works like a charm!! Thank you!!
bkan
Posts: 51
Joined: November 6th, 2013, 8:33 am

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!!
beginUndoGroup
Posts: 81
Joined: November 27th, 2012, 6:41 am

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.
Post Reply