背景:winform程序,需要点击某个按钮时,弹出系统键盘TabTip.exe,这个键盘文件一般位于C:\Program Files\Common Files\microsoft shared\ink下面。
问题:见下图
补充:我是通过以下的代码调用键盘文件的
var commonFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles);
//程序集目标平台为X86时,获取到的是x86的Program Files,但TabTip.exe始终在Program Files目录下
if (commonFilesPath.Contains("Program Files (x86)"))
{
commonFilesPath = commonFilesPath.Replace("Program Files (x86)", "Program Files");
}
var tabTipPath = Path.Combine(commonFilesPath, @"microsoft shared\ink\TabTip.exe");
var processStartInfo = new ProcessStartInfo
{
FileName = tabTipPath,
UseShellExecute = true,
CreateNoWindow = true
};
Process.Start(processStartInfo);
//第一次系统软键盘启动时候,需要缓冲一下
Thread.Sleep(50);
虽然我有办法获取到这个键盘的句柄,但是尝试获取键盘里面的控件,返回却是0个元素。
所以也就无法获取“手写”控件元素
真的没有办法对这个“手写“控件进行点击操作了吗?恳求大家帮忙,感谢大家!
如果你正在使用 WinForms,那么可能无法直接获取 TabTip.exe 键盘的内部控件,因为它不是一个窗口控件,而是一个独立的程序。因此,你需要使用其他方法来间接地触发键盘的操作。
一种方法是使用 Windows API 函数,如 SendMessage 或 PostMessage,来向键盘发送消息,以模拟用户的点击事件。
下面是一个使用 SendMessage 函数的示例代码:
private const int WM_LBUTTONDOWN = 0x0201;
private const int WM_LBUTTONUP = 0x0202;
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
private void ClickButton()
{
// 获取键盘的句柄
IntPtr keyboardHandle = GetKeyboardHandle();
if (keyboardHandle != IntPtr.Zero)
{
// 发送鼠标左键按下消息
SendMessage(keyboardHandle, WM_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero);
// 发送鼠标左键抬起消息
SendMessage(keyboardHandle, WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero);
}
}
private IntPtr GetKeyboardHandle()
{
// 你需要自己实现这个函数,以获取 TabTip.exe 键盘的句柄
// 可以使用 EnumWindows 函数和 GetWindowText 函数来查找键盘的窗口
// ...
}
这只是一个示例,具体的实现可能需要根据实际情况进行调整。请注意,使用 SendMessage 或 PostMessage 发送消息可能会对系统造成影响,请谨慎选择;
提供一个思路,你可尝试用按键精灵自动化脚本,查看下是否可以定位相关坐标或者元素
You can use the Windows Input Simulator (C# SendInput Wrapper - Simulate Keyboard and Mouse) library to trigger the handwriting pad in the soft keyboard. You can find the library at https://inputsimulator.codeplex.com/.
望采纳
方法一
// 触发软键盘中的手写板
var proc = new Process();
proc.StartInfo.FileName ="tabtip.exe";
proc.StartInfo.Arguments = "/handwriting";
proc.Start();
方法二
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "C:\\Windows\\System32\\TabTip.exe";
Process.Start(startInfo);
方法三
您可以使用InputPanel.ShowDialog()方法触发软键盘中的手写板,如下所示:
InputPanel inputPanel = new InputPanel();
inputPanel.ShowDialog();
建议考虑从注册表找一下能否设置调用虚拟键盘的时候的默认值修改为调用手写版的属性值。说不定可以 你可以尝试一下
你可以使用 System.Windows.Forms.SendKeys 类来触发软键盘中的手写板功能。
// Using statement
using System.Windows.Forms;
// Trigger the handwriting pad.
SendKeys.Send("+{F7}");