[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] PATCH: Pass keyboard scancodes to Python



Hi,

this has been added to subversion.

Committed revision 993.

Cheers,

On 3/21/07, Quentin Smith <quentin@xxxxxxx> wrote:
Hi-

I've recently written a few apps with pygame, and noted that the
multimedia keys on my keyboard produce a keycode of 0 in keydown/up
events. This patch also passes the OS-dependent scancode for the key into
Python. Though not useful for identifying keys generically, it could be
useful for allowing you to set a per-machine or per-user key binding.
Right now, I'm using it with Freevo to bind the volume up/down keys on my
keyboard.

diff -ur pygame-1.7.1release_orig/src/event.c pygame-1.7.1release/src/event.c
--- pygame-1.7.1release_orig/src/event.c        2005-08-15 07:11:40.000000000 -0400
+++ pygame-1.7.1release/src/event.c     2007-03-19 21:46:10.000000000 -0400
@@ -250,6 +250,7 @@
         case SDL_KEYUP:
                 insobj(dict, "key", PyInt_FromLong(event->key.keysym.sym));
                 insobj(dict, "mod", PyInt_FromLong(event->key.keysym.mod));
+               insobj(dict, "scancode", PyInt_FromLong(event->key.keysym.scancode));
                 break;
         case SDL_MOUSEMOTION:
                 obj = Py_BuildValue("(ii)", event->motion.x, event->motion.y);


Thanks, --Quentin