-->

How to post Extended ASCII chars (0x80 to 0xFF) us

2019-07-20 06:31发布

问题:

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