views:

28

answers:

2

Hi!
I'm want do someStuff() when CTRL-C pressed. I had wrote some code, but it "not enough good". What can I do with it?)

    //org.eclipse.draw2d.Shape getShape(){....}

    getShape().addKeyListener(new KeyListener(){

        @Override
        public void keyPressed(KeyEvent ke) {
        }

        @Override
        public void keyReleased(KeyEvent ke) {
            /*if CTRL-C pressed*/
            if((ke.getState() & KeyEvent.CONTROL) != 0 && 'c' == ('a' + ke.character - 1)){
                someStuff();
            } 
        }
    });

Thanks.

A: 

Try using the following condition to check for CTRL-C:

public void keyReleased(KeyEvent event) {
  if (event.getKeyCode() == KeyEvent.VK_C && event.getModifiers() == InputEvent.CTRL_MASK)
    someStuff();
}
Andy
@Andy : org.eclipse.draw2d.KeyEvent doesn't contain any VK_C and so on. I'm sorry if I formulate question in some not obvious form.
Stas
Aah, my mistake. I don't know how to help you then =/.
Andy
+1  A: 

Try this:

getShape().addListener(SWT.KeyUp, new Listener() {
    public void handleEvent(Event event) {
        if (event.stateMask == SWT.CTRL && event.keyCode == 'c') {
            someStuff();
        }
    }});
True Soft