Skip to content

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

Closed
@GlazLafee

Description

@GlazLafee

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions