def _qkey_to_ascii(event):
    """
    (Try to) convert the Qt key event to the corresponding ASCII sequence for
    the terminal. This works fine for standard alphanumerical characters, but
    most other characters require terminal specific control_modifier sequences.
    The conversion below works for TERM="linux' terminals.
    """
    if sys.platform == 'darwin':
        control_modifier = QtCore.Qt.MetaModifier
    else:
        control_modifier = QtCore.Qt.ControlModifier
    ctrl = int(event.modifiers() & control_modifier) != 0
    if ctrl:
        if event.key() == QtCore.Qt.Key_P:
            return b'\x10'
        elif event.key() == QtCore.Qt.Key_N:
            return b'\x0E'
        elif event.key() == QtCore.Qt.Key_C:
            return b'\x03'
        elif event.key() == QtCore.Qt.Key_L:
            return b'\x0C'
        elif event.key() == QtCore.Qt.Key_B:
            return b'\x02'
        elif event.key() == QtCore.Qt.Key_F:
            return b'\x06'
        elif event.key() == QtCore.Qt.Key_D:
            return b'\x04'
        elif event.key() == QtCore.Qt.Key_O:
            return b'\x0F'
        elif event.key() == QtCore.Qt.Key_V:
            return QtWidgets.qApp.clipboard().text().encode('utf-8')
        else:
            return None
    else:
        if event.key() == QtCore.Qt.Key_Return:
            return '\n'.encode('utf-8')
        elif event.key() == QtCore.Qt.Key_Enter:
            return '\n'.encode('utf-8')
        elif event.key() == QtCore.Qt.Key_Tab:
            return '\t'.encode('utf-8')
        elif event.key() == QtCore.Qt.Key_Backspace:
            return b'\x08'
        elif event.key() == QtCore.Qt.Key_Delete:
            return b'\x06\x08'
        elif event.key() == QtCore.Qt.Key_Enter:
            return '\n'.encode('utf-8')
        elif event.key() == QtCore.Qt.Key_Home:
            return b'\x1b[H'
        elif event.key() == QtCore.Qt.Key_End:
            return b'\x1b[F'
        elif event.key() == QtCore.Qt.Key_Left:
            return b'\x02'
        elif event.key() == QtCore.Qt.Key_Up:
            return b'\x10'
        elif event.key() == QtCore.Qt.Key_Right:
            return b'\x06'
        elif event.key() == QtCore.Qt.Key_Down:
            return b'\x0E'
        elif event.key() == QtCore.Qt.Key_PageUp:
            return b'\x49'
        elif event.key() == QtCore.Qt.Key_PageDown:
            return b'\x51'
        elif event.key() == QtCore.Qt.Key_F1:
            return b'\x1b\x31'
        elif event.key() == QtCore.Qt.Key_F2:
            return b'\x1b\x32'
        elif event.key() == QtCore.Qt.Key_F3:
            return b'\x00\x3b'
        elif event.key() == QtCore.Qt.Key_F4:
            return b'\x1b\x34'
        elif event.key() == QtCore.Qt.Key_F5:
            return b'\x1b\x35'
        elif event.key() == QtCore.Qt.Key_F6:
            return b'\x1b\x36'
        elif event.key() == QtCore.Qt.Key_F7:
            return b'\x1b\x37'
        elif event.key() == QtCore.Qt.Key_F8:
            return b'\x1b\x38'
        elif event.key() == QtCore.Qt.Key_F9:
            return b'\x1b\x39'
        elif event.key() == QtCore.Qt.Key_F10:
            return b'\x1b\x30'
        elif event.key() == QtCore.Qt.Key_F11:
            return b'\x45'
        elif event.key() == QtCore.Qt.Key_F12:
            return b'\x46'
        elif event.text() in ('abcdefghijklmnopqrstuvwxyz'
                              'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
                              '[],=-.;/`&^~*@|#(){}$><%+?"_!'
                              "'\\ :"):
            return event.text().encode('utf8')
        else:
            return None