Reputation: 5116
I have a button in a group widget and i simply want to create a keyboard shortcut(enter) so that the button action gets called and focused.Interestingly what happened is when i press space(on keyboard)the respective button action gets called which doesn't work with enter.Eventually all I'm trying to get is simply press enter so that button action triggers.Any ideas so that i can play-around it.
Upvotes: 4
Views: 2805
Reputation: 12718
The Enter key (SWT.CR
) does not invoke the current button, but rather the default button of the Shell
. You set the default button with
shell.setDefaultButton(button);
Upvotes: 6
Reputation: 3155
Maybe what you're searching for is the method #addKeyListener of class Button. Implement a KeyListener and in the #keyReleased(KeyEvent keyEvent) method evaluate keyEvent like this: if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) { //your code here}
Upvotes: 1