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
Adds function to pygame.key module to get key code from name of key #1694
Conversation
Great. Can you also add |
I think this needs to be more clear in the docs what this is returning. Mention something about it matching K_* event types and an example like your unit test below? Example:
::
>>> pygame.key.key_code("return") == pygame.K_RETURN
True
>>> pygame.key.key_code("0") == pygame.K_0
True
>>> pygame.key.key_code("space") == pygame.K_SPACE
True
.. ## pygame.key.key_code ## We still want to be able to compile with SDL 1 for pygame 2. #if IS_SDLv1
/* maybe return 0? How would code that has to work on pygame 1 and 2 work? */
#else /* IS_SDLv2 */
/*... your code goes here.*/
#endif /* IS_SDLv2 */ The SDL docs for SDL_GetKeyFromName have this note:
So your code needs to either raise an error if you get SDLK_UNKNOWN? Or should it just return 0? Maybe raising an error is better. |
Added two exceptions:
And I added the example documentation suggested by @illume. |
Thanks 👍, I will approve this changes now, but since we are close to the release date I will let illume to decide if we merge it in dev8 or later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 thanks
Attempt to add a function to get a key code from a key name. There were some concerns in the original report #309 that this function wouldn't be SDL1 compatible but I'm not sure if that is a huge concern any more.
Also, do I need to add a:
into the docs?
It's my first first attempt at adding a C extension Function so I may have done some obvious stuff wrong!