开发者

SWT Cross-Platform Enter Detection

开发者 https://www.devze.com 2022-12-10 05:34 出处:网络
I have a global filter (Display.addFilter) in SWT in which I want to detect Enter key. In Windows, pressing Enter generates SWT.CR in \'keyCode\' part of KeyListener event. Is this assumption safe for

I have a global filter (Display.addFilter) in SWT in which I want to detect Enter key. In Windows, pressing Enter generates SWT.CR in 'keyCode' part of KeyListener event. Is this assumption safe for all platforms, or should I check if

keyCode == SWT.开发者_运维技巧CR || keyCode == SWT.LF?

Thanks.


If you want to catch the event when the user presses the Enter key while a widget is in focus, use a TraverseListener or a Listener with type SWT.Traverse. Then, you check

if (event.detail == SWT.TRAVERSE_RETURN) {
    // The user pressed Enter 
}
0

精彩评论

暂无评论...
验证码 换一张
取 消