在业余时间开发我的SmartNote过程中,遇到需要截获复制、粘贴等特殊按键。
在Eclipse SWT的编程中,除了需要keycode外,还要配合Event的stateMask来一起判断,如下是代码片段:
public void keyPressed(KeyEvent e) {
System.out.println(e.keyCode);
if (e.keyCode == 13) {
String key = text.getText();
} else if (e.stateMask == SWT.CTRL && e.keyCode == 'v') {
text.paste();
} else if (e.stateMask == SWT.CTRL && e.keyCode == 'x') {
text.cut();
} else if (e.stateMask == SWT.CTRL && e.keyCode == 'c') {
text.copy();
}
}