Skip to content
This repository was archived by the owner on Nov 23, 2019. It is now read-only.
This repository was archived by the owner on Nov 23, 2019. It is now read-only.

api to read key by enum #59

Open
Open

Description

@ensonic

Not sure if it is already possible. At least there is not example in the test and I can't figure it out.

RIght now one can do:

  k = Key()
  if k.enter:

but there is no way to pass e.g. Key.CODE.ENTER to a function and then e.g. do

def check_key(key):
  k = Key()
  return k.status(key)

I can do

getattr(k, 'enter')

and there is

print Key.CODE.enum_dict
{'RIGHT': 106, 'UP': 103, 'DOWN': 108, 'BACKSPACE': 14, 'ENTER': 28, 'LEFT': 105}

but

print Key.CODE.ENTER.name
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute 'name'

I first thought that should work: https://docs.python.org/3/library/enum.html#creating-an-enum, but you are not using enum34, but your own.

Regarding more key api, see also
ev3dev/ev3dev-lang#90

Activity

  1. ensonic commented on Jul 21, 2015

    @ensonic
    Author

    I am using this for now:

    getattr(k, Key.CODE.enum_dict.keys()[0].lower())
    
  2. topikachu commented on Aug 3, 2015

    @topikachu
    Owner

    Would you please create a pull request?

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions