

def OnKey(self, event):
    '        Key event handler. If the key is in the ASCII range, write it to the\n        serial port. Newline handling and local echo is also done here.\n        '
    code = event.GetUnicodeKey()
    if (code < 256):
        code = event.GetKeyCode()
    if (code == 13):
        if self.settings.echo:
            char.text_ctrl_output.AppendText('\n')
        if (self.settings.newline == NEWLINE_CR):
            self.serial.write(b'\r')
        elif (self.settings.newline == NEWLINE_LF):
            self.serial.write(b'\n')
        elif (self.settings.newline == NEWLINE_CRLF):
            self.serial.write(b'\r\n')
    else:
        char = unichr(code)
        if self.settings.echo:
            self.WriteText(char)
        self.serial.write(char.encode('UTF-8', 'replace'))

dataset/ETHPy150Open pyserial/pyserial/examples/wxTerminal.py TerminalFrame.OnKey/VarMisuse@58/129 `self`->`char`