Вопрос

I need to automate entering a certain character (Russian letter Э). In Spy++ the corresponding message looks like this:

WM_CHAR chCharCode: '221' (221) cRepeat:1 ScanCode:28 fExtended:0 fAltDown:0 fRepeat:0 fUp:0

enter image description here

In order to send this message programmatically, I use this Delphi code:

SendMessage(Self.PassengerGrid, WM_CHAR, WPARAM(221), LPARAM($280001));

When I examine the results of running my code in Spy++, I see following message:

WM_CHAR chCharCode: '89' (89) cRepeat:1 ScanCode:28 fExtended:0 fAltDown:0 fRepeat:0 fUp:0

Something must be wrong with wParam of my SendMessage call.

How can I fix it (so that the chCharcode is equal to 221)` ?

Update 1:

  • The machine, where this error occurs, has two keyboard languages - English and Russian.
  • I noticed that when the following code

    SendMessage(MyGridHandle, WM_KEYDOWN, VK_OEM_7, LPARAM($390000)); SendMessage(MyGridHandle, WM_CHAR, WPARAM(221), LPARAM($280001)); SendMessage(MyGridHandle, WM_KEYUP, VK_OEM_7, LPARAM($c0390001));

is executed, the selected language (according to tray icon) changes from Russian to English.

  • Whatever character I transmit in WM_CHAR, WPARAM of the message is always 0x59 (89).

Update 2: Using WM_UNICHAR instead of WM_CHAR doesn't help.

Это было полезно?

Решение

You should send UTF-16 code of a character as WPARAM (that is 1069 for Russian 'Э'), ex:

procedure TForm1.Button1Click(Sender: TObject);
begin
  PostMessage(Edit1.Handle, WM_CHAR, WPARAM(1069), LPARAM(0));//$280001));
end;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top