简体   繁体   English

屏幕键盘-Windows 8.1平板电脑

[英]On Screen keyboard - Windows 8.1 Tablet

we've been working on an application for the past 5 years, and we're just now getting to where we want the program to run on the surface pro 3, the main problem we're running into is the on-screen keyboard does not open when a textbox is clicked. 在过去的5年中,我们一直在致力于应用程序的开发,而现在我们要让程序在Surface Pro 3上运行,我们遇到的主要问题是屏幕键盘单击文本框时无法打开。

i am trying to find a way, to bind an application wide event that would open the keyboard anytime a textbox is touched, is this possible, or do we need to go through the entire application and fire the keyboard manually anytime we think we'll need it? 我正在尝试找到一种方法来绑定一个应用程序范围的事件,该事件将在每次触摸文本框时打开键盘,这是否可能,还是我们需要遍历整个应用程序并在我们认为我们会在任何时候手动触发键盘需要它?

除非在WindowsStoreApplication中,否则单击或触摸文本框时似乎无法打开键盘。

I Created a keyboard function and found this answer somewhere else on here about 2 months ago. 我创建了一个键盘功能,大约2个月前在这里的其他地方找到了这个答案。 If i can find it again I will update this with the link. 如果我可以再次找到它,我将使用链接对其进行更新。 I am using a Surface 2 pro tablet and the code is: 我正在使用Surface 2 pro平板电脑,代码为:

 class KeyboardFunction
{
    //Used for close keyboard method
    [DllImport("user32.dll")]
    public static extern int FindWindow(string lpClassName, string lpWindowName);

    [DllImport("user32.dll")]
    public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);

    public const int WM_SYSCOMMAND = 0x0112;
    public const int SC_CLOSE = 0xF060;
    //End close keyboard inputs


    /*
   *Opens the tablet keyboard on device
   *
   */
    public void openKeyboardOnTablet()
    {
        System.Diagnostics.Process.Start(@"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe");

    }

    /*
  *Close on screen keyboard
  *
  */
    public void closeOnscreenKeyboard()
    {
        // retrieve the handler of the window  
        int iHandle = FindWindow("IPTIP_Main_Window", "");
        if (iHandle > 0)
        {
            // close the window using API        
            SendMessage(iHandle, WM_SYSCOMMAND, SC_CLOSE, 0);
        }
    }

}

As far as I am aware there is no way to tell the surface to open up the keyboard with only numbers. 据我所知,没有办法告诉表面只用数字打开键盘。 This just opens the default keyboard. 这只是打开默认键盘。 I have tried to include the surface dll but that did nothing in my c# desktop application. 我试图包括Surface dll,但是在我的C#桌面应用程序中什么也没做。 Hope this helps! 希望这可以帮助!

Here is one way to do it in Windows 8.1 with WPF, and this code can be used in Windows 10 as well except that you may have to make modifications to work better with the new Touch Panel and Handwriting Service : 这是在带有WPF的Windows 8.1中执行此操作的一种方法,该代码也可以在Windows 10中使用,除了您可能需要进行修改以更好地与新的Touch Panel and Handwriting Service

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Interactivity;
using System.Windows.Threading;

    public class KeyboardFocusBehavior : Behavior<Control>
    {
        public bool Focused
        {
            get { return (bool)GetValue(FocusedProperty); }
            set { SetValue(FocusedProperty, value); }
        }
        public static readonly DependencyProperty FocusedProperty = DependencyProperty.Register("Focused", 
            typeof(bool), 
            typeof(ControlKeyboardFocusBehavior), 
            new PropertyMetadata(false, OnFocusedPropertyChanged));

        private static void OnFocusedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ControlKeyboardFocusBehavior b = d as ControlKeyboardFocusBehavior;

            if(b != null && b.AssociatedObject != null)
            {
                Control c = b.AssociatedObject;

                if (!c.IsFocused && (bool)e.NewValue)
                {
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(delegate()
                    {
                        c.Focus();         
                        Keyboard.Focus(c);
                        TouchKeyboard.Show();
                    }));
                }
            }
        }

    public class ShowTouchKeyboardOnFocusBehavior : Behavior<Control>
    {
        protected override void OnAttached()
        {
            base.OnAttached();
            WeakEventManager<Control, KeyboardFocusChangedEventArgs>.AddHandler(AssociatedObject, "GotKeyboardFocus", OnGotKeyboardFocus);
            WeakEventManager<Control, KeyboardFocusChangedEventArgs>.AddHandler(AssociatedObject, "LostKeyboardFocus", OnLostKeyboardFocus);
        }

        private void OnGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            // show the touch keyboard
            TouchKeyboard.Show();
            var textBox = sender as TextBox;
            if (textBox != null)
                textBox.SelectionStart = Math.Max(0, textBox.Text.Length);
        }

        private void OnLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            // hide the touch keyboard
            TouchKeyboard.Hide();
        }
    }

Then in the WPF XAML file, for a given textbox: 然后在WPF XAML文件中,对于给定的文本框:

                        <Border  CornerRadius="0,5,5,0" Style="{StaticResource TextBoxBorder}" >
                            <TextBox Style="{StaticResource TextBoxInput}" Text="{Binding MyTextProperty}" >
                                <i:Interaction.Behaviors>
                                    <behaviors:ShowTouchKeyboardOnFocusBehavior />
                                </i:Interaction.Behaviors>
                            </TextBox>
                        </Border>   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM