简体   繁体   中英

Java - How to match event.keycode with colon : slash / backslash \ asterisk * question mark ? double quotes " lessthan < greater than > pipe |

I am validating Textbox input

        name.addKeyListener(new KeyListener() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == 131072) {
                e.doit = false;
                return;
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
            // TODO Auto-generated method stub
        }
    });

I can only use org.eclipse.swt.events.KeyEvent I cannot use any other. I do not wish to match with integer like 131072, is there any constant that is available to match with e.keycode . Also I want to match < > : \\ / * " | .

Thanks in Advance :)

For ordinary characters you should use the character field of the KeyEvent :

if (e.character == '<')

The SWT class contains key code constants for things that are not characters. Such as SWT.F1 , SWT.ARROW_UP , SWT.HOME .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM