function write_field(where_x, where_y, width, height: integer): string; //!Вызывается _функция_ var what_string, temp_char, last_char: string; what_key: integer; lowcase, pntr: boolean; template_str: array [0..12] of string; begin template_str[1] := '.,?''"1-()@/:_'; template_str[2] := 'ABC2'; template_str[3] := 'DEF3'; template_str[4] := 'GHI4'; template_str[5] := 'JKL5'; //это строки, откуда template_str[6] := 'MNO6'; //берутся символы template_str[7] := 'PQRS7'; //переменная lowcase template_str[8] := 'TUV8'; //может менять регистр template_str[9] := 'WXYZ9'; template_str[10] := ' 0'; template_str[11] := '*#'; SetColor(255, 255, 255); FillRect(where_x, where_y, width, height); SetColor(0, 255, 0); DrawRect(where_x, where_y, width, height); Font(0); Color(255, 0, 0, 0); repaint; //рисуем собственно поле time := GetRelativeTimeMs; lowcase := false; //переменная нижнего регистра pntr := true; //переменная отображения текстового курсора repeat //пошёл цикл опроса if what_key <> 0 then previous_key := what_key; key:=GetKeyClicked; key1:=KeyToAction(GetKeyPressed); what_key := 0; if key = KE_KEY1 then what_key:=1; //присваиваем спецкод if key = KE_KEY2 then what_key:=2; if key = KE_KEY3 then what_key:=3; if key = KE_KEY4 then what_key:=4; if key = KE_KEY5 then what_key:=5; if key = KE_KEY6 then what_key:=6; if key = KE_KEY7 then what_key:=7; if key = KE_KEY8 then what_key:=8; if key = KE_KEY9 then what_key:=9; if key = KE_KEY0 then what_key:=10; if key = KE_STAR then what_key:=11; if key = KE_POUND then //* - отвечает за регистр begin lowcase := not lowcase; if lowcase = true then for i := 1 to 11 do template_str[i] := locase(template_str[i]); else for i := 1 to 11 do template_str[i] := upcase(template_str[i]); end; if (previous_key <> what_key) and (what_key <> 0) then begin //сравниваем, если нажатая и клавиша до этого - разные for i:=1 to 12 do key_counter[what_key]:=0; //обнуляем счётчики key_counter[what_key] := 1; //а счётчик нужной клавиши на 1 last_char := temp_char; what_string:=what_string+last_char; temp_char := ''; last_char := ''; end else if (previous_key = what_key) and (what_key <> 0) then begin time := GetRelativeTimeMs; key_counter[what_key]:=key_counter[what_key]+1; end; if key_counter[what_key] > length(template_str[what_key]) then //обеспечиваем цикличность key_counter[what_key] := 1; //символов if key1 = GA_LEFT then //клавиша влево - стирает последний символ begin if length(what_string) <= 1 then what_string := '' else what_string := Copy(what_string, 0, length(what_string) - 1); end; else if what_key <> 0 then temp_char:=GetChar(template_str[what_key], key_counter[what_key]-1); SetColor(255, 255, 255); //начинаем всё рисовать FillRect(where_x, where_y, width, height); SetColor(0, 0, 0); DrawRect(where_x, where_y, width, height); DrawString(what_string+temp_char, where_x + 1, where_y + 2); if pntr then DrawLine(where_x + textwidth(what_string+temp_char) + 1, where_y + 2, where_x + textwidth(what_string+temp_char) + 1, where_y + textheight + 1); pntr := not pntr; repaint; //отрисовка if (GetRelativeTimeMs - time > 2000) or (GetRelativeTimeMs < time) or (key1 = GA_RIGHT) then begin for i := 0 to 12 do key_counter[what_key] := 0; time := GetRelativeTimeMs; //прошло 2 секунды last_char := temp_char; //или нажали "вправо"? what_string:=what_string+last_char; //тогда обнуляем счётчики temp_char := ''; last_char := ''; end; delay(200); until key1 = GA_FIRE; //"огонь" - заканчиваем редактировать write_field := what_string; //готовая строка end;