pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill van Melle <bill.van.me...@gmail.com>
Subject OS variation in key listeners
Date Tue, 22 Mar 2011 01:20:00 GMT
This is a followup to that thread (
people thought was getting too long.

I followed Chris's advice about making Window focusable -- create a trivial

public class FocusableWindowSkin extends WindowSkin {
 public boolean isFocusable() {
return true;

and install it in my app's startup method

    Theme.getTheme().set(Window.class, FocusableWindowSkin.class);

Then when I want to create a brand new OS window
with DesktopApplicationContext.createDisplay, I tell the Pivot Window that I
put in the OS window to requestFocus(), which now succeeds.  After that it's
just a matter of handling key strokes.

On Windows XP, the following works for me to intercept the Escape key as a
shortcut for closing the window:

this.getComponentKeyListeners().add(new ComponentKeyListener.Adapter() {
    public boolean keyTyped(Component component, char character) {
        if (character == Keyboard.KeyCode.ESCAPE) {
            return true;
        return false;

(where closeHostWindow does this.getDisplay().getHostWindow().dispose(); --
is that the right thing?)

However, on Mac OS X and Ubuntu Linux, it doesn't work.  At first I thought
it might be something about key codes, but I set a breakpoint, and keyTyped
doesn't get called at all.  The following alternative *does* work on all 3

this.getActionMappings().add(new ActionMapping(
    new Keyboard.KeyStroke(Keyboard.KeyCode.ESCAPE, 0),
    new Action() {
        public void perform(Component source) {

Although I'm vaguely curious why this should be so, I'm mainly putting this
out as a FYI for anyone searching on this topic.

View raw message