Java Code Examples for org.eclipse.jface.bindings.keys.KeyStroke#getModifierKeys()

The following examples show how to use org.eclipse.jface.bindings.keys.KeyStroke#getModifierKeys() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyBindingHelper.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private static boolean internalMatchesKeybinding(int keyCode, int stateMask, TriggerSequence seq)
{
	KeySequence keySequence = (KeySequence) seq;
	KeyStroke[] keyStrokes = keySequence.getKeyStrokes();

	if (keyStrokes.length > 1)
	{
		return false; // Only handling one step binding... the code below does not support things as "CTRL+X R" for
						// redo.
	}
	for (KeyStroke keyStroke : keyStrokes)
	{
		if (keyStroke.getNaturalKey() == keyCode && keyStroke.getModifierKeys() == stateMask)
		{

			return true;
		}
	}
	return false;
}
 
Example 2
Source File: EmacsMovementHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Does the trigger for this movement command contain the SHIFT key?
 * 
 * Enforce that the <binding> and <binding>+SHIFT belong to the same Command. 
 * If not, don't apply shift selection (if enabled) for this command (i.e. return false).
 *  
 * @param event the Execution event that invoked this command
 * 
 * @return true if SHIFT modifier was set, else false
 */
private boolean getShifted(ExecutionEvent event) {
	// NB: only single keystroke commands are valid 
	boolean result = false;
	Object trigger = event.getTrigger();
	Event e = null;
	if (trigger != null && trigger instanceof Event && ((e = (Event)trigger).stateMask & SWT.SHIFT )!= 0) {
		String cmdId = event.getCommand().getId();
		int mask = (e.stateMask & SWT.MODIFIER_MASK) ^ SWT.SHIFT;
		int u_code = Character.toUpperCase((char)e.keyCode);
		IBindingService bs = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class);
		if (cmdId != null && bs != null) {
			TriggerSequence[] sequences = bs.getActiveBindingsFor(cmdId);
			for (TriggerSequence s : sequences) {
				if (s instanceof KeySequence) {
					KeyStroke[] strokes = ((KeySequence)s).getKeyStrokes();
					if (strokes.length == 1) {
						KeyStroke k = strokes[strokes.length - 1];
						// if keyCode is alpha, then we test uppercase, else keyCode
						if (k.getModifierKeys() == mask
								&& (k.getNaturalKey() == u_code || k.getNaturalKey() == e.keyCode)) {
							result = true;
							break;
						}
					}
				}
			}
		} 
	}
	return result;
}
 
Example 3
Source File: UniversalHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
private Event makeEvent(IUniversalResult ua) {
	Event result = new Event();
	KeySequence keys = ua.getTrigger();
	if (keys != null) {
		Trigger[] triggers = keys.getTriggers();
		if (triggers[0] instanceof KeyStroke) {	// really, all it can be anyway
			KeyStroke ks = (KeyStroke)triggers[triggers.length - 1];
			result.keyCode = ks.getNaturalKey();
			result.stateMask = ks.getModifierKeys() & SWT.MODIFIER_MASK;
		}
	}
	return result;
}
 
Example 4
Source File: KeyBindingHelper.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean matchesKeybinding(int keyCode, int stateMask, KeySequence keySequence) {
    KeyStroke[] keyStrokes = keySequence.getKeyStrokes();

    for (KeyStroke keyStroke : keyStrokes) {

        if (keyStroke.getNaturalKey() == keyCode
                && ((keyStroke.getModifierKeys() & stateMask) != 0 || keyStroke.getModifierKeys() == stateMask)) {

            return true;
        }
    }
    return false;
}