如何将 Enter 作为快捷键分配给 Eclipse RCP 应用程序中的按钮
我在组小部件中有一个按钮,我只想创建一个键盘快捷键(输入),以便调用按钮操作并聚焦。有趣的是,当我按空格(键盘上)时,会调用相应的按钮操作,但不会不能与 Enter 一起使用。最终我想要得到的只是简单地按 Enter 键,以便触发按钮操作。任何想法,以便我可以尝试它。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Enter 键 (
SWT.CR
) 不会调用当前按钮,而是调用Shell
的默认按钮。您可以使用以下命令设置默认按钮The Enter key (
SWT.CR
) does not invoke the current button, but rather the default button of theShell
. You set the default button with也许您正在寻找的是 Button 类的方法 #addKeyListener。实现一个KeyListener,并在#keyReleased(KeyEvent keyEvent)方法中评估keyEvent,如下所示:
if (e.keyCode == SWT .CR || e.keyCode == SWT.KEYPAD_CR) { //此处为您的代码}
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}