版本说明,用于版本CEF4_87.0.4280.141,cef_binary_87.1.14。为什么要用这个版本,因为这是最后一个支持flash的版本。

新增OSR模式组件,在最后

主要功能

1、支持非OSR模式下中文输入。

2、支持输入框和富文本框输入。

文本输入

 

3、输入法选择框跟随输入光标移动。

GIF 2026-1-23 19-51-16

 

4、支持H5元素拖动。

拖动

 

使用说明

一、下载libcefcninput.so放在与应用程序和CEFbinary同一目录下。先确保您的CEF浏览器运行正常,进行后台操作。
二、在CEF显示页面加上
1、在全局里加
uses
Gtk2Globals,gtk2;

type
TintInputDll=procedure (InChromium: TChromium;InCEFShow:TWinControl;In_im_context: PGtkIMContext;In_isDebug:Boolean); stdcall;
ToutInputDll= procedure; stdcall;
TSetInputWait=procedure (WaitMs:int64); stdcall;
TGetInputWait=function:Int64; stdcall;
var
intInputDll:TintInputDll;
outInputDll:ToutInputDll;
SetInputWait:TSetInputWait;
GetInputWait:TGetInputWait;
HndDLL: THandle;
2、在FormCreate事件中加
var
IntAddr,OutAddr,GetWaitAddr,SetWaitAddr: Pointer;

//加载动态库
HndDLL := LoadLibrary('./libcefcninput.so');
IntAddr:=GetProcAddress(HndDLL, 'intInputDll');
OutAddr:=GetProcAddress(HndDLL, 'outInputDll');
GetWaitAddr:=GetProcAddress(HndDLL,'GetInputWait');
SetWaitAddr:=GetProcAddress(HndDLL,'SetInputWait');
if Assigned(IntAddr) and Assigned(OutAddr) then
begin
intInputDll:=TintInputDll(IntAddr);
outInputDll:=ToutInputDll(OutAddr);
GetInputWait:=TGetInputWait(GetWaitAddr);
SetInputWait:=TSetInputWait(SetWaitAddr);
intInputDll(Chromium1,CEFLinkedWindowParent1,im_context,false); //初始化中文输入法组件
end
else
ShowMessage('加载中文输入组件出错,不能输入中文。');
3、在FormCloseQuery事件中加
if HndDLL<>0 then
begin
outInputDll;
UnloadLibrary(HndDLL);
HndDLL:=0;
end;
三、函数说明
1、初始化中文输入法
procedure intInputDll(InChromium: TChromium;InCEFShow:TWinControl;In_im_context: PGtkIMContext;In_isDebug:Boolean);
In_isDebug是否输出坐标等信息
2、退出中文输入法
procedure outInputDll;
3、设置输入等待时间
主要用于部分输入法在英文状态时不会由输入法输出英文字符,等待判断是否是输入英文。
系统初始化时会根据计算机运行速度设置一个初始值。
如果出现中文状态时首字母输入到浏览器时才要手动设置。X86系统设置为10以上比较安全;arm和arm64最小20,50比较安全
procedure SetInputWait(WaitMs:int64);
4、得到当前输入等待时间
function GetInputWait():Int64;

 ============OSR模式组件使用==========================

一、下载libcefosrcninput.so放在与应用程序和CEFbinary同一目录下。先确保您的CEF浏览器运行正常,进行后台操作。

二、在CEF显示面加上
1、在全局里加
type
TInitInputCNDll=procedure (ChromiumIn: TChromium;PanelIn: TBufferPanel;In_isDebug:Boolean); stdcall;
TQuitInputCNDll= procedure; stdcall;
var
InitInputCNDll:TInitInputCNDll;
QuitInputCNDll:TQuitInputCNDll;
HndDLL: THandle;
2、在FormCreate事件中加
var
IntAddr,OutAddr: Pointer;

HndDLL := LoadLibrary('./libcefosrcninput.so');
IntAddr:=GetProcAddress(HndDLL, 'InitInputCNDll');
OutAddr:=GetProcAddress(HndDLL, 'QuitInputCNDll');
if Assigned(IntAddr) and Assigned(OutAddr) then
begin
InitInputCNDll:=TInitInputCNDll(IntAddr);
QuitInputCNDll:=TQuitInputCNDll(OutAddr);
InitInputCNDll(Chromium1,Panel1,True); //初始化中文输入法组件
end
else
ShowMessage('加载中文输入组件出错,不能输入中文。');

3、在FormHide事件中加
QuitInputCNDll;

4、禁用原来FormCreate事件中的ConnectKeyPressReleaseEvents(PGtkWidget(Panel1.Handle)); 
三、函数说明
1、初始化中文输入法
procedure InitInputCNDll(ChromiumIn: TChromium;PanelIn: TBufferPanel;In_isDebug:Boolean);
PanelIn是OSR模式渲染窗口
In_isDebug是否输出坐标等信息
2、退出中文输入法
procedure QuitInputCNDll;

总结:OSR模式无法拖动。还是用非OSR更好。

通过网盘分享的文件:Cef中文输入组件
链接: https://pan.baidu.com/s/12bUcaPgp8chahGkmBnxOmw?pwd=cefc 提取码: cefc

posted on 2026-01-21 23:33  禁卫军  阅读(81)  评论(1)    收藏  举报