主题
发送字符串2 - SendString2
函数简介
向指定窗口发送文本数据(UTF-8)。与 SendString 的核心差异:发送前强制异步打开中文输入法(切换布局 + 打开 IME)。
字符投递使用 PostMessageW(WM_CHAR);Edit/RichEdit 仍优先 EM_REPLACESEL。
风险提示
部分程序(游戏、金融客户端等)对布局切换 / 打开 IME 过敏,可能导致卡死或无响应。默认场景请优先使用 SendString;仅当目标窗必须开输入法才能正确输入中文时再用本接口。
接口名称
SendString2DLL调用
int SendString2(long ola, long hwnd, string str);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| hwnd | 长整数型 | 目标窗口句柄。为 0 时使用当前 绑定窗口。 |
| str | 字符串 | 要发送的文本数据(UTF-8)。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int ret = ola.SendString2(hwnd, "你好");csharp
using OLAPlug;
var ola = new OLAPlugServer();
int ret = ola.SendString2(hwnd, "你好");python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
ret = ola.SendString2(hwnd, "你好")java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
int ret = ola.SendString2(hwnd, "你好");go
import "github.com/ola/olaplug/olaplug"
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
ret := ola.SendString2(hwnd, "你好")rust
use olaplug::OLAPlugServer;
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let ret = ola.send_string2(&hwnd, "你好");cpp
var ola = com("OlaPlug.OlaSoft")
var ret = ola.SendString2(hwnd, "你好")vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ret = ola.SendString2(hwnd, "你好")text
.局部变量 ola, OLAPlug
ola.创建 ()
ret = ola.SendString2(hwnd, “你好”)aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var ret = ola.SendString2(hwnd, "你好");text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
整数 ret = ola.SendString2(hwnd, "你好")cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int32_t ret = ola.SendString2(hwnd, "你好");原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
SendString2(instance, hwnd, "你好");csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int SendString2(long ola, long hwnd, string str);
long instance = CreateCOLAPlugInterFace();
SendString2(instance, hwnd, "你好");python
from ctypes import CDLL, c_int64
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ola.SendString2(instance, hwnd, "你好".encode("utf-8"))返回值
| 返回值 | 说明 |
|---|---|
1 | 成功。 |
0 | 失败。 |
注意事项
| 项目 | 说明 |
|---|---|
| 与 SendString 差异 | 仅本接口会主动打开输入法;SendString 不打开。 |
| 卡死风险 | 布局切换通过异步 PostMessage 完成,仍可能导致个别程序异常,请先小范围验证。 |
| 发送间隔 | 字符间隔受 SetConfig 中键盘延时(如 KeyDownInterval)影响。 |
