Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle key presses using swt


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.

like image 577
Stan Kurilin Avatar asked Oct 06 '10 18:10

Stan Kurilin


1 Answers

Try this:

getShape().addListener(SWT.KeyUp, new Listener() {
    public void handleEvent(Event event) {
        if (event.stateMask == SWT.CTRL && event.keyCode == 'c') {
            someStuff();
        }
    }});
like image 111
True Soft Avatar answered Oct 11 '22 11:10

True Soft