Skip to main content
gamedev.net
🔒 Locked

[java] SWT and listeners problem

Started by MattL920 0 replies 400+ views
Original Post
MattL920
MattL920
Hi everybody I'm writing an SWT interface for a simple java game I'm designing (basically just an excuse to learn SWT), and I'm having a problem incorporating a listener to register keyboard input. Since I want this listener to have as wide a scope as possible, I'm incorporating it into the shell. My basic code for this is: Listener listener = new Listener() { public void handleEvent(Event e) { // switch statements for key inputs and stuff here } } shell.addListener(SWT.KeyDown, listener); I know this code works in theory, since I created a test program which just initialized a shell and added the listener. Everything worked fine. The problem is that in my real program, as soon as I add any other components which might gain the focus and take it away from the shell, the listener doesn't work. So it looks like a listener can only work if the component it's attached to has the focus. Is there any way to create a listener which could operate regardless of what has the focus? I was hoping adding it to the shell would do it, but apparently that doesn't work. I'd really appreciate any help, this has been frustrating me for a while now. Thanks
misterX
misterX
proposition:
add the same key listener to all the components subject of having focus.
I know it's no nice & clean solution... but it should work at least.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.