Strange WM_CHAR behaviour (wrong chCharCode)

时光怂恿深爱的人放手 提交于 2020-01-03 02:48:27

问题


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

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.


回答1:


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;


来源:https://stackoverflow.com/questions/12954545/strange-wm-char-behaviour-wrong-chcharcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!