如何在Delphi中使用PostMessage发布扩展ASCII字符(0x80到0xFF)?
我正在编写一个键盘映射程序应用程序,其中需要将扩展ASCII字符(0x80到0xFF)发送到当前窗口。我试过下面的每一种方法如何在Delphi中使用PostMessage发布扩展ASCII字符(0x80到0xFF)?,delphi,keyboard-events,postmessage,win64,extended-ascii,Delphi,Keyboard Events,Postmessage,Win64,Extended Ascii,我正在编写一个键盘映射程序应用程序,其中需要将扩展ASCII字符(0x80到0xFF)发送到当前窗口。我试过下面的每一种方法 function ConstructLParam(vKey: Word): LongInt; // Cardinal; begin { ConstructLParam } if vKey > $FF then Result := LongInt(MapVirtualKeyW(vKey, 0) and $00000FFF or $F000) shl 16
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 }
但这些在Win64中都不起作用(它在Win32下可以正常工作):(
任何人都可以帮助,如何发布扩展ASCII字符(0x80到0xFF)
提前感谢Windows不使用扩展ASCII。它使用Unicode,并且有一个ANSI层用于后台兼容。停止使用ANSI。现在是2016年。使用Unicode。为什么你要用这种方式伪造输入。正确的方法是使用
SendInput
。在任何情况下,使用自动化不是更好吗?如果你正在努力使用这种代码并且必须这样做这样,为什么不考虑做一些调试呢?为什么程序员现在不知道如何调试?没有学习调试的人怎么可能是程序员?我们应该把你的网络从你这里拿走一个月,强迫你去学习如何调试!!!戴维,这个应用程序对Unicode很好(而且UTO 0x7F也是如此)。问题只在于0x80到0xFF,我需要这样做,因为有很多数据是使用旧的方言fontsSee创建的,也就是说,LPARAM
在Win64中是64位的,而不是像cide假设的32位,所以您应该在ConstructLParam()中使用LPARAM
而不是LongInt
,或者使用MAKELPARAM()
代替手动位移位。谢谢,实际上我需要这些代码才能在Win32和Win64中工作