我有一台平板电脑必须运行带有数字输入字段的应用程序。但是,我在弹出显示数字小键盘的Windows键盘(TabTip.exe)时遇到问题。
单击文本字段时,键盘需要自动弹出。
我设法通过在TextBox事件处理程序中运行TabTip.exe来显示每个字段上的键盘,但它显示了正常的键盘布局。这是使用这个问题的答案:Show & hiding the Windows 8 on screen keyboard from WPF
protected override void OnStartup(StartupEventArgs eventArgs)
{
// Popup keyboard, Select All on getting focus.
EventManager.RegisterClassHandler(typeof(TextBox), UIElement.GotFocusEvent,
new RoutedEventHandler(GotFocus_Event), true);
EventManager.RegisterClassHandler(typeof(TextBox), UIElement.LostFocusEvent,
new RoutedEventHandler(LostFocus_Event), true);
}
private static void GotFocus_Event(object sender, RoutedEventArgs e)
{
// The popup keyboard.
OpenTouchKeyboard(sender, e);
}
private static void OpenTouchKeyboard(object sender, RoutedEventArgs e)
{
var textBox = e.OriginalSource as TextBox;
if (textBox != null && IsSurfaceKeyboardAttached())
{
var path = @"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe";
Process.Start(path);
textBox.BringIntoView();
}
}
我在下一页中读到您可以使用文本框" InputScope"属性,以指示它应该是一个数字小键盘。
类似于<TextBox Header="Name" InputScope="Number"/>
然而,这没有任何效果,它仍然会弹出常规布局。此外,我发现很难相信InputScope只是将自己传递给TabTip.exe进程的执行,而没有某种方式将它们连接起来。
我也遇到过这样的问题:Start TabTip with numpad view open建议在每次调用TabTip.exe之前编辑注册表,但这看起来非常混乱,在Windows 10中显然不可靠。
是否有命令行参数或可以传递给它的东西?
答案 0 :(得分:1)
我已经找到了答案,感谢MSDN指出Automatic Touch Keyboard。
所以基本上我一直都是错误的方式
正确的方法:添加对InputPanelConfigurationLib.dll
和UIAutomationClient.dll
然后禁用墨水输入......
using System;
using System.Reflection;
using System.Windows.Input;
namespace ModernWPF.Win8TouchKeyboard.Desktop
{
public static class InkInputHelper
{
public static void DisableWPFTabletSupport()
{
// Get a collection of the tablet devices for this window.
TabletDeviceCollection devices = System.Windows.Input.Tablet.TabletDevices;
if (devices.Count > 0)
{
// Get the Type of InputManager.
Type inputManagerType = typeof(System.Windows.Input.InputManager);
// Call the StylusLogic method on the InputManager.Current instance.
object stylusLogic = inputManagerType.InvokeMember("StylusLogic",
BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
null, InputManager.Current, null);
if (stylusLogic != null)
{
// Get the type of the stylusLogic returned from the call to StylusLogic.
Type stylusLogicType = stylusLogic.GetType();
// Loop until there are no more devices to remove.
while (devices.Count > 0)
{
// Remove the first tablet device in the devices collection.
stylusLogicType.InvokeMember("OnTabletRemoved",
BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic,
null, stylusLogic, new object[] { (uint)0 });
}
}
}
}
}
}
并在MainWindow.xaml.cs
...
public MainWindow()
{
InitializeComponent();
// Disables inking in the WPF application and enables us to track touch events to properly trigger the touch keyboard
InkInputHelper.DisableWPFTabletSupport();
this.Loaded += MainWindow_Loaded;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
System.Windows.Automation.AutomationElement asForm =
System.Windows.Automation.AutomationElement.FromHandle(new WindowInteropHelper(this).Handle);
InputPanelConfigurationLib.InputPanelConfiguration inputPanelConfig = new InputPanelConfigurationLib.InputPanelConfiguration();
inputPanelConfig.EnableFocusTracking();
}
瞧,选择一个文本框可以调出键盘。但是,现在,它会关注InputScope
,如果我设置为Number
会导致显示数字小键盘。