Kruptein 15 Posting Whiz in Training

The SetValue() and GetValue() are to complicated, but it should work with WriteText()... although this always prints a newline if I press the space button...?

def OnKeyDown(self, event):
        insp=self.text_ctrl_1.GetInsertionPoint()
        words=self.text_ctrl_1.GetValue().split(" ") #get all the words
        hl=[["in","red"]]  #syntax list All words=in should become red
        prev="" #previous words processed
        wordcount=0
        for word in words:
            for lh in hl:
                if lh[0]==word:  #if word=="in"
                    if wordcount>0:  #if word is not first word
                        self.text_ctrl_1.BeginTextColour('red')
                        self.text_ctrl_1.WriteText(word)  #print "in" in red
                        self.text_ctrl_1.EndTextColour()
                        prev+=" "+word
                    elif wordcount==0:  #if word is first word (You can Ignore this part)
                        self.text_ctrl_1.SetValue("")
                        self.text_ctrl_1.BeginTextColour('red')
                        self.text_ctrl_1.WriteText(word)  #print "in" in red
                        self.text_ctrl_1.EndTextColour()
                        prev=word
                else:  #if word!="in"
                    if wordcount>0: #if word is not first word
                        self.text_ctrl_1.BeginTextColour('black')
                        self.text_ctrl_1.WriteText(word) #print word
                        self.text_ctrl_1.EndTextColour()
                        prev+=" "+word
                    elif wordcount==0: #if word is first word
                        self.text_ctrl_1.SetValue("")
                        self.text_ctrl_1.BeginTextColour('black')
                        self.text_ctrl_1.WriteText(word) #print word
                        self.text_ctrl_1.EndTextColour()
                        prev=word
            wordcount+=1
        self.text_ctrl_1.SetInsertionPoint(insp)
        event.Skip()