def normalize_keystr(keystr):
 keystr = keystr.lower()
 replacements = (('control', 'ctrl'), ('windows', 'meta'), ('mod1', 'alt'), ('mod4', 'meta'))
 for (orig, repl) in replacements:
  keystr = keystr.replace(orig, repl)
 for mod in ['ctrl', 'meta', 'alt', 'shift']:
  keystr = keystr.replace((mod + '-'), (mod + '+'))
 return keystr

def normalize_keystr ( keystr ) : keystr = keystr . lower ( ) replacements = ( ( 'control' , 'ctrl' ) , ( 'windows' , 'meta' ) , ( 'mod1' , 'alt' ) , ( 'mod4' , 'meta' ) ) for ( orig , repl ) in replacements : keystr = keystr . replace ( orig , repl ) for mod in [ 'ctrl' , 'meta' , 'alt' , 'shift' ] : keystr = keystr . replace ( ( mod + '-' ) , ( mod + '+' ) ) return keystr
normalize a keystring like ctrl-q to a keystring like ctrl+q .