Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyEvent's key attribute and modifier keys in WX backend #1880

Closed
GlazLafee opened this issue Apr 3, 2013 · 4 comments
Closed

KeyEvent's key attribute and modifier keys in WX backend #1880

GlazLafee opened this issue Apr 3, 2013 · 4 comments

Comments

@GlazLafee
Copy link

I just notice that "key" attribute of KeyEvent has changed when modifier keys are activated (e.g. previously "up", now "ctrl+up"). I have updated my code but i report that "key" attribute is sometimes wrong. When Alt or Ctrl are pressed, "key" attribute is respectively "alt" and "control" but, when Alt or Ctrl are released, "key" is "alt+alt" and "ctrl+control". I suggest to add a test before loop which prefixes "key" with modifier keys.

def _get_key(self, evt):

        keyval = evt.m_keyCode
        if keyval in self.keyvald:
            key = self.keyvald[keyval]
        elif keyval < 256:
            key = chr(keyval)
            # wx always returns an uppercase, so make it lowercase if the shift
            # key is not depressed (NOTE: this will not handle Caps Lock)
            if not evt.ShiftDown():
                key = key.lower()
        else:
            key = None

        # Adds a test to prevent this issue.
        if key not in ("alt", "control"):
            for meth, prefix in (
                                 [evt.AltDown, 'alt'],
                                 [evt.ControlDown, 'ctrl'], ):
                if meth():
                    key = '{0}+{1}'.format(prefix, key)

        return key
@pelson
Copy link
Member

pelson commented Apr 3, 2013

I'd agree this is a bug.

FWIW (and others seeing this) the documentation for the keys can be found here: http://matplotlib.org/api/backend_bases_api.html#matplotlib.backend_bases.KeyEvent. In essence, the fact that alt+control is a valid key combination is mentioned.

The only thing to watch out for is what happens when the two ctrl buttons are pressed - should the result be ctrl+control?

@tacaswell
Copy link
Member

@YannGoudard Is this still an issue on master (I don't have wx on this machine to test)? There has been a bunch of work recently improving the modifier key handling of several of the backends.

@GlazLafee
Copy link
Author

@tacaswell I have tested master and this bug no longer exists.

@tacaswell
Copy link
Member

@YannGoudard Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants