Search code examples
javakeyboardswtmodifier

Modifier Key state


I have a tiny (rikiki) problem in SWT ...

I am making a small class extending org.eclipse.swt.widgets.Composite and which is supposed to be nested in an RCP app ...

In this small class I have widgets which are supposed to react to mouse or keyboard event

BUT

I need to use modifier keys (Shift/Ctrl/Alt/...) to alter my coponents behaviours when I click them or send them keyboard event ...

The probleme is that I cannot just listen for mod-key striking because my user can strike it out from my component and then click it...

I cannot use a display filter to avoid disturbing the shell that nests my component.(but may be it will be my last solution in case there is no other solution)

I cannot make a transparent component that reads and dispatch events to all of my components because it would, at the most, be as large as my component and wont get mod-key strikes from the shell out my component (or even out from the shell) ...

Do anyone have any idea?


Solution

  • More or less it is like

    myComponent.add<Any>Listener(new <Appropriate>Listener(){
        @Override
        public void <AppropriateMethod>(like KeyPress)>(<Appropriate>Event e) {
            int stateMask=e.stateMask;
            if((stateMask & SWT.ALT)==SWT.ALT){
                <Do_appropriate_actions>;
            }
            if((stateMask & SWT.CTRL)==SWT.CTRL){
                <Do_another_appropriate_actions>;
            }
            if((stateMask & SWT.SHIFT)==SWT.SHIFT){
                <Do_an_even_more_appropriate_actions_cause_you_are_kind_of_a_code_roxxor_!>;
            }
        };
    };

    Hope it helps ...