View previous topic :: View next topic |
Author |
Message |
ebo
Joined: 19 Dec 2005 Posts: 1
|
Posted: Mon Dec 19, 2005 10:20 am Post subject: KeyListener |
|
|
Code: |
shell.handleKeyDown(this, &onShellKeyDownEvent);
private void onShellKeyDownEvent(KeyEvent e)
{
if(isShellClickDisable)
return;
else
{
MessageBox.showMsg("!!");
enableAllWidget(true);
}
}
|
this is some part of my code
I try grep keyEvent on Shell but I can't grep that.
why I can't?
I use addKeyListener and KeyListener but they don't work too...
[/code] |
|
Back to top |
|
|
Shawn Liu
Joined: 09 Mar 2005 Posts: 104 Location: Shanghai, China
|
Posted: Sat Dec 24, 2005 1:11 am Post subject: |
|
|
try the following code, use listener, delegate or both.
Code: | private import dwt.all;
class Test{
private static Shell shell;
this(Display display){
this.shell = new Shell(display);
// method (1)
{
shell.addKeyListener(new class KeyListener{
public void keyPressed(KeyEvent e) {
// shell.setText("keyPressed by listener " ~ e.toString());
}
public void keyReleased(KeyEvent e) {
// shell.setText("key Released by listener " ~ e.toString());
}
});
} // end of method (1)
// method (2)
{
shell.handleKeyDown(null, &onShellKeyDownEvent);
shell.handleKeyUp(null, &onShellKeyUpEvent);
} // end of method
}
Shell open(){
shell.open();
return shell;
}
void onShellKeyDownEvent(KeyEvent e){
shell.setText("keyPressed by delegate " ~ cast(char)e.character);
}
void onShellKeyUpEvent(KeyEvent e){
shell.setText("keyReleased by delegate " ~ cast(char)e.character);
}
static void main(char[][] args) {
Display display = new Display();
Shell shell = (new Test(display)).open();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
void main(char[][] args){
Test.main(args);
} |
|
|
Back to top |
|
|
|