Tabtip和InputScope - 显示数字键盘
我有一台平板电脑,必须使用数字输入字段运行应用程序。但是,我无法使Windows键盘(TabTip.exe)在默认情况下弹出显示数字键盘。Tabtip和InputScope - 显示数字键盘
当文本框被点击时,键盘需要自动弹出。
我设法让它通过在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
是不是有一个命令行参数还是可以传递给它的东西?
我找到了答案,谢谢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
,则会显示数字小键盘。
这是在Windows 10上工作吗? – walteronassis