Author: Attila Torda-Pilisi
Replace chracters while typing
This code allows you to replaces umlauts (i.e. 'ä', 'ö', etc.) with 'ae', 'oe',
etc. while typing.
Answer:
1
2 procedure TForm1.AppOnMessage(var Msg: TMsg; var Handled: Boolean);
3 type
4 TReplacement = record
5 chIn: Char;
6 chOut: string[2]
7 end;
8 TReplacements = array[0..6] of TReplacement;
9 const
10 Replacements: TReplacements = ((chIn: 'ä'; chOut: 'ae'),
11 (chIn: 'ö'; chOut: 'oe'),
12 (chIn: 'ü'; chOut: 'ue'),
13 (chIn: 'Ä'; chOut: 'Ae'),
14 (chIn: 'Ö'; chOut: 'Oe'),
15 (chIn: 'Ü'; chOut: 'Ue'),
16 (chIn: 'ß'; chOut: 'ss'));
17 var
18 i: Integer;
19 c: Char;
20 begin
21 Handled := False;
22 if Msg.message = WM_CHAR then
23 begin
24 if Chr(Msg.wParam) in ['ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', 'ß'] then
25 begin
26 for i := Low(Replacements) to High(Replacements) do
27 if Chr(Msg.wParam) = Replacements[i].chIn then
28 begin
29 Msg.wParam := Ord(Replacements[i].chOut[1]);
30 with Longrec(Msg.lParam) do
31 Hi := (Hi and $FF00) or VKKeyScan(Replacements[i].chOut[2]);
32 PostMessage(Msg.hwnd, WM_CHAR, Ord(Replacements[i].chOut[2]),
33 Msg.wParam);
34 with Longrec(Msg.lParam) do
35 Hi := (Hi and $FF00) or VKKeyScan(Char(Msg.wParam));
36 Break;
37 end;
38 end;
39 end;
40 end;
41
42 procedure TForm1.FormCreate(Sender: TObject);
43 begin
44 Application.OnMessage := AppOnMessage;
45 end;
|