Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SWT Cross-Platform Enter Detection

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.

like image 408
Mohsen Avatar asked Nov 06 '09 15:11

Mohsen


1 Answers

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 
}
like image 163
True Soft Avatar answered Nov 16 '22 09:11

True Soft