5.4.1 KeyEvent object

The KeyEvent class is passed as argument to the KEY_PRESS and KEY_RELEASE events. The class contains the attributes key, keycode and mods (see the constructor for a description).

class KeyEvent( key, keycode, mods=0)
key is a unicode string that contains the key that was pressed or released. The key is the translated key which means that it may depend on other keys (such as Shift) or previously pressed keys. For example, if you just press the 'a' key you receive a lower case 'a', but if you press Shift and 'a' then you will get an upper case 'A'.

keycode is the code of the untranslated key that was pressed or released. The values for common keys are defined in the keydefs module (i.e. KEY_LEFT, KEY_UP, etc.).

mods contains the modifier flags which is a combination of KEYMOD_SHIFT, KEYMOD_CONTROL, KEYMOD_ALT and KEYMOD_META. The respective flag is set if the Shift, Control, Alt or Meta key was pressed while the event key was pressed or released.

shiftKey( )
Return True if the key is a Shift key (no matter if it is the left or right key).

controlKey( )
Return True if the key is a Control key (no matter if it is the left or right key).

altKey( )
Return True if the key is an Alt key (no matter if it is the left or right key).