Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Detecting keys while showing a context menu
Detecting keys while showing a context menu [message #1060156] Thu, 23 May 2013 07:20 Go to next message
Christophe Bouhier is currently offline Christophe Bouhier
Messages: 895
Registered: July 2009
Senior Member
Hello,

Is there a way to detect which key (or better accelator Ctrl, Shift or
Alt) during a right click on a control?

I have tried attaching a SWT.KeyDown listener on a Menu Widget, but no
event comes in.

I would appreciate, if someone has done this and could hint me. The use
case is to have differentiate the action for a MenuItem depending on if
Ctrl is pressed.

Thank You,
Christophe Bouhier
Re: Detecting keys while showing a context menu [message #1060196 is a reply to message #1060156] Thu, 23 May 2013 09:09 Go to previous messageGo to next message
Vijay Raj
Messages: 608
Registered: July 2009
Senior Member
When you get a selection event on a menu item, the SelectionEvent object contains a variable called stateMask, this represents the keybord states if any..
	/**
	 * The state of the keyboard modifier keys at the time
	 * the event was generated.
	 */
	public int stateMask;


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: Detecting keys while showing a context menu [message #1060202 is a reply to message #1060196] Thu, 23 May 2013 09:33 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe Bouhier
Messages: 895
Registered: July 2009
Senior Member
On 23-05-13 15:09, Vijay Raj wrote:
> When you get a selection event on a menu item, the SelectionEvent object
> contains a variable called stateMask, this represents the keybord states
> if any..
>
> /**
> * The state of the keyboard modifier keys at the time
> * the event was generated.
> */
> public int stateMask;
Great, this could be usefull. I am afraid however this gets lost on the
JFace abstraction of a SelectionChangedEvent. Are there any ways around
this? (CC Jface forum)


*** from StructuredViewer

/**
* Handles a select event from the widget.
* <p>
* This method is internal to the framework; subclassers should not call
* this method.
* </p>
*
* @param event
* the SWT selection event
*/
protected void handleSelect(SelectionEvent event) {
// handle case where an earlier selection listener disposed the control.
Control control = getControl();
if (control != null && !control.isDisposed()) {
updateSelection(getSelection());
}
}
>
Re: Detecting keys while showing a context menu [message #1060398 is a reply to message #1060202] Fri, 24 May 2013 09:25 Go to previous message
Vijay Raj
Messages: 608
Registered: July 2009
Senior Member
I thought you were talking about a menu or menu item,
Is it a table viewer or any jface viewer?

one possibility is that you can get the actual table or control from the viewer and add a selection listener , so that you can capture that mask and use it in your actual jface selection change event.


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Previous Topic:Merging cells in a Word table through OleAutomation
Next Topic:How to keep Popup-menu open after selection event?
Goto Forum:
  


Current Time: Tue Jul 22 03:29:18 EDT 2014

Powered by FUDForum. Page generated in 0.01610 seconds