How to post Extended ASCII chars (0x80 to 0xFF) using PostMessage in Delphi?

倖福魔咒の 提交于 2019-12-12 17:50:41

问题


I am writing a Keyboard Mapper Application in which I need to send Extended ASCII chars (0x80 to 0xFF) to Current Window. I have tried everything like below

function ConstructLParam(vKey: Word): LongInt; // Cardinal;
begin { ConstructLParam }
  if vKey > $FF then
    Result := LongInt(MapVirtualKeyW(vKey, 0) and $00000FFF or $F000) shl 16 or 1
  else
    Result := LongInt(MapVirtualKey(vKey, 0) and $000000FF or $FF00) shl 16 or 1;
end; { ConstructLParam }

procedure PostCharacter(TargetWinHandle: Hwnd; UniCodeValue: Word; IME_MSG, WideFunction, SimulateKey, SendMSG: Boolean);
begin { PostCharacter }
  if SendMSG then  // SendMSG Fn
    if IME_MSG then //  IME Msg
      if WideFunction then //  Wide Fn
        begin
          if SimulateKey then
            SendMessageW(TargetWinHandle, WM_IME_KEYDOWN, MakeWParam(UniCodeValue, 0), ConstructLParam(UniCodeValue));
          SendMessageW(TargetWinHandle, WM_IME_CHAR, MakeWParam(UniCodeValue, 0), ConstructLParam(UniCodeValue));
          if SimulateKey then
            SendMessageW(TargetWinHandle, WM_IME_KEYUP, MakeWParam(UniCodeValue, 0), (ConstructLParam(UniCodeValue) or $C0000000));
        end
      else                 //  Not Wide Fn
        begin
          if SimulateKey then
            SendMessage(TargetWinHandle, WM_IME_KEYDOWN, MakeWParam(UniCodeValue, 0), ConstructLParam(UniCodeValue));
          SendMessage(TargetWinHandle, WM_IME_CHAR, MakeWParam(UniCodeValue, 0), ConstructLParam(UniCodeValue));
          if SimulateKey then
            SendMessage(TargetWinHandle, WM_IME_KEYUP, MakeWParam(UniCodeValue, 0), (ConstructLParam(UniCodeValue) or $C0000000));
        end
    else            //  Not IME Msg
      if WideFunction then //  Wide Fn
        begin
          if SimulateKey then
            SendMessageW(TargetWinHandle, WM_KEYDOWN, MakeWParam(UniCodeValue, 0), ConstructLParam(UniCodeValue));
          SendMessageW(TargetWinHandle, WM_CHAR, MakeWParam(UniCodeValue, 0), ConstructLParam(UniCodeValue));
          if SimulateKey then
            SendMessageW(TargetWinHandle, WM_KEYUP, MakeWParam(UniCodeValue, 0), (ConstructLParam(UniCodeValue) or $C0000000));
        end
      else                 //  Not Wide Fn
        begin
          if SimulateKey then
            SendMessage(TargetWinHandle, WM_KEYDOWN, MakeWParam(UniCodeValue, 0), ConstructLParam(UniCodeValue));
          SendMessage(TargetWinHandle, WM_CHAR, MakeWParam(UniCodeValue, 0), ConstructLParam(UniCodeValue));
          if SimulateKey then
            SendMessage(TargetWinHandle, WM_KEYUP, MakeWParam(UniCodeValue, 0), (ConstructLParam(UniCodeValue) or $C0000000));
        end
  else             // Not SendMSG Fn
    if IME_MSG then //  IME Msg
      if WideFunction then //  Wide Fn
        begin
          if SimulateKey then
            PostMessageW(TargetWinHandle, WM_IME_KEYDOWN, MakeWParam(UniCodeValue, 0), ConstructLParam(UniCodeValue));
          PostMessageW(TargetWinHandle, WM_IME_CHAR, MakeWParam(UniCodeValue, 0), ConstructLParam(UniCodeValue));
          if SimulateKey then
            PostMessageW(TargetWinHandle, WM_IME_KEYUP, MakeWParam(UniCodeValue, 0), (ConstructLParam(UniCodeValue) or $C0000000));
        end
      else                 //  Not Wide Fn
        begin
          if SimulateKey then
            PostMessage(TargetWinHandle, WM_IME_KEYDOWN, MakeWParam(UniCodeValue, 0), ConstructLParam(UniCodeValue));
          PostMessage(TargetWinHandle, WM_IME_CHAR, MakeWParam(UniCodeValue, 0), ConstructLParam(UniCodeValue));
          if SimulateKey then
            PostMessage(TargetWinHandle, WM_IME_KEYUP, MakeWParam(UniCodeValue, 0), (ConstructLParam(UniCodeValue) or $C0000000));
        end
    else            //  Not IME Msg
      if WideFunction then //  Wide Fn
        begin
          if SimulateKey then
            PostMessageW(TargetWinHandle, WM_KEYDOWN, MakeWParam(UniCodeValue, 0), ConstructLParam(UniCodeValue));
          PostMessageW(TargetWinHandle, WM_CHAR, MakeWParam(UniCodeValue, 0), ConstructLParam(UniCodeValue));
          if SimulateKey then
            PostMessageW(TargetWinHandle, WM_KEYUP, MakeWParam(UniCodeValue, 0), (ConstructLParam(UniCodeValue) or $C0000000));
        end
      else
        begin
          if SimulateKey then
            PostMessage(TargetWinHandle, WM_KEYDOWN, MakeWParam(UniCodeValue, 0), ConstructLParam(UniCodeValue));
          PostMessage(TargetWinHandle, WM_CHAR, MakeWParam(UniCodeValue, 0), ConstructLParam(UniCodeValue));
          if SimulateKey then
            PostMessage(TargetWinHandle, WM_KEYUP, MakeWParam(UniCodeValue, 0), (ConstructLParam(UniCodeValue) or $C0000000));
        end;

end; { PostCharacter }

But none of this works in Win64 (it use to work fine under Win32) :(

Can anybody please help, how to post Extended ASCII chars (0x80 to 0xFF) ?

Thanks in Advance

来源:https://stackoverflow.com/questions/38330335/how-to-post-extended-ascii-chars-0x80-to-0xff-using-postmessage-in-delphi

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