What is wrong with this small code ? lazarus / 9-Editor ---------------------------------------------------------------------- GoDxNero · 2009-10-19 20:19 Well I want so that once I type this word 'asd' i will receive a var procedure ........onkeypress..... begin    if key = 'a' then      if key = 's' then        if key = 'd' then        a := 5; end; how to write it the correct way ? ---------------------------------------------------------------------- alter · 2009-10-19 21:47 for example: create global variable key_state: integer; set it to 0 on application startup and then: Code: [Select]procedure ........onkeypress..... begin    case key of      'a': if key_state = 0 then key_state:=1;      's': if key_state = 1 then key_state:=2;      'd': if key_state = 2 then begin          key_state:=0;          a:=5;        end;    end; end; ---------------------------------------------------------------------- Martin_fr · 2009-10-19 21:54 ..OnKeyPress is called once for each keypress. So if someone types asd then there are 3 calls to the event. your code assumes that key is a s and d at the *same* time => which will never be true. you need to keep a "state" (a common thing in all software development). For this you need to store the value of the state in a place where it will persist between the individual calls to the OnKeyPress events. Best to do is to create a Member (variable) in the object. Assuming that this is  Form1.Edit1KeyPress => then TForm1 is the object that should have your state variable. TForm1 = class   .... //lots of automatically created stuff  private    asdState: Integer; .... procedure ........onkeypress..... begin    if key = 'a' then asdState := 1    else    if key = 's' and asdState = 1 then asdState := 2    else    if key = 'd' and asdState = 0 then begin        a:=5        asdState := 0;    end    else        asdState := 0; end; Now if asdState is 1, we know the previous key was an "a". It will be increased by one, if the next correct char is enterred. Any other char will reset it, so the whole sequence must be entered again. ---------------------------------------------------------------------- Martin_fr · 2009-10-19 21:58 @alter always prefer a variable on the object, over a global. global variables are harder to maintain on the long run. Your code does not reset the  key_state  if any other char is pressed. so it will also work for axysxyd The case is preferable over the multi-if that I used => +1 ---------------------------------------------------------------------- alter · 2009-10-20 11:35 Sorry, I was writing it late night:-) Ofc case needs also else part and by global i meant out of procedure ofc ---------------------------------------------------------------------- GoDxNero · 2009-10-20 14:49 It actually not works private     { private declarations }     cheatState: Integer; procedure TForm1.FormKeyPress(Sender: TObject; var Key: char); begin   if key = 'h' then cheatState := 1   else   if (key = 'a') and (cheatState = 1) then cheatState := 2   else   if (key = 'i') and (cheatState = 2) then   begin     correct:=10;     Label1.Caption := 'Level 10 of 10';     Form1.Color := clBlack;     resets;     cheatState := 0;   end   else cheatState := 0; end; Edit : Sorry It works ! I forget 'keyPreview' = true