def funkeypress():
    """
    Waits for the user to press any key including function keys. Returns 
    the ascii code for the key or the scancode for the function key.
    """
    import msvcrt
    while 1:
        if msvcrt.kbhit():                  # Key pressed?
            a = ord(msvcrt.getch())         # get first byte of keyscan code  
            if a == 0 or a == 224:          # is it a function key?
                b = ord(msvcrt.getch())     # get next byte of key scan code
                x = a + (b*256)             # cook it.
                return x                    # return cooked scancode
            else:
                return a                    # else return ascii code

    Waits for the user to press any key including function keys. Returns 
    the ascii code for the key or the scancode for the function key.
    
recipes/Python/197140_Key_press_detectiWindows_text_only_console/recipe-197140.py