def get_key_map():
    """
    Returns the corrisponding Key based on the current status (modifier) and the keycode of the key typed.
         char = f(keycode, modifier)
    Where char is the corresponding character given by the combination.
    """
    table = Popen("xmodmap -pke", shell=True, bufsize=1, stdout=PIPE).stdout
    key_map = {}
    for line in table:
        m = re.match('keycode +(\d+) = (.+)', line.decode())
        if m:
            l = m.groups()[1].split()
            # Wipes out all the useless elements that appears in xmodmap
            nl = []
            for i in range(len(l)):
                if i==0: #NORMAL
                    nl.append(l[i])
                if i==1: #SHIFT_L
                    nl.append(l[i])
                if i==3: #SHIFT_R
                    nl.append(l[i])
                if i==4: # ISO_LEVEL3_SHIFT
                    nl.append(l[i])
                if i==5: # SHIFT_?_ALT_R
                    nl.append(l[i])
                    nl.append(l[i])

            seq = [transform.get(letter.upper(), letter) for letter in nl]
            # Add None element for the rest of the table
            seq.extend([None for i in range(len(mod_keys)-len(seq))])
            # Pad out with the remained extended combinations
            seq.extend([mod+'+'+str(seq[0]) for mod in ext_mod_keys])
            
            assert len(seq)==len(mod_keys)+len(ext_mod_keys), \
                   "Err:"+str(seq)+" has not the same size of "+str(mod_keys)+str(ext_mod_keys)
            
            key_map[m.groups()[0]] = {}
            for mod, s in zip(mod_keys+ext_mod_keys, seq):
                key_map[m.groups()[0]][mod] = s
            
    return key_map

    Returns the corrisponding Key based on the current status (modifier) and the keycode of the key typed.
         char = f(keycode, modifier)
    Where char is the corresponding character given by the combination.
    
recipes/Python/577952_Parser_Keylogger_based_Finite_State/recipe-577952.py