How to assign input as shortcutKey for a button in an Eclipse RCP application

I have a button in a group widget, and I just want to create a key combination (enter) so that the button action is called and focused. I wonder what happened when I press the spacebar (on the keyboard), the corresponding button action gets which does not work with enter.Eventually everything I try to get, just press enter to activate the button action. All the ideas so that I can get around them.

+4
source share
2 answers

The Enter key ( SWT.CR ) does not call the current button, but the default Shell button. You set the default button with

 shell.setDefaultButton(button); 
+5
source

You may be looking for the #addKeyListener method of the Button class. Deploy the KeyListener , and in #keyReleased (KeyEvent keyEvent) evaluate the keyEvent method: if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) { //your code here}

+1
source

Source: https://habr.com/ru/post/1381916/


All Articles