代码之家  ›  专栏  ›  技术社区  ›  Saher Ahwal

触摸屏键盘

  •  2
  • Saher Ahwal  · 技术社区  · 15 年前

    我一直在开发一个触摸屏应用程序。我需要知道是否有一个现成的触摸屏键盘,我可以作为我的应用程序的控制器使用。

    我试过使用windows-ready键盘,但对于触摸屏来说太小了。

    Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) + Path.DirectorySeparatorChar + "osk.exe");
    

    任何想法如何开始建立一个在最短的时间将不胜感激。。。。

    我从某人处复制了此代码并对其进行了一些修改:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Windows;
    using System.Diagnostics;
    using System.IO;
    using System.Runtime.InteropServices;
    
    
     class Win32
    {
    [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
    public static extern bool SetWindowPos(
    int hWnd, // window handle
    int hWndInsertAfter, // placement-order handle
    int X, // horizontal position
    int Y, // vertical position
    int cx, // width
    int cy, // height
    uint uFlags); // window positioning flags
    public const int HWND_BOTTOM = 0x0001;
    public const int HWND_TOP = 0x0000;
    public const int SWP_NOSIZE = 0x0001;
    public const int SWP_NOMOVE = 0x0002;
    public const int SWP_NOZORDER = 0x0004;
    public const int SWP_NOREDRAW = 0x0008;
    public const int SWP_NOACTIVATE = 0x0010;
    public const int SWP_FRAMECHANGED = 0x0020;
    public const int SWP_SHOWWINDOW = 0x0040;
    public const int SWP_HIDEWINDOW = 0x0080;
    public const int SWP_NOCOPYBITS = 0x0100;
    public const int SWP_NOOWNERZORDER = 0x0200;
    public const int SWP_NOSENDCHANGING = 0x0400;
    }
    
    
    namespace Keyboard
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                this.KeyText.MouseDoubleClick += new MouseEventHandler(KeyText_MouseDoubleClick);
    
            }
            private Process process;
            private string getKeyboardText()
            {
                KeyScreen k = new KeyScreen();
                k.ShowDialog();
                if (k.DialogResult.ToString().Equals("OK"))
                    return k.Text1;
                else
                    return null;
            }
    
            void KeyText_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                this.KeyText.Text = getKeyboardText();
            }
    
            private void KeyBtn_Click(object sender, EventArgs e)
            {
    
                this.showKeypad();
    
                //Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) + Path.DirectorySeparatorChar + "osk.exe");
            }
            private void showKeypad()
            {
                Process process = new Process();
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError = true;
                process.StartInfo.CreateNoWindow = true;
                process.StartInfo.FileName = "c:\\Windows\\system32\\osk.exe";
                process.StartInfo.Arguments = "";
                process.StartInfo.WorkingDirectory = "c:\\";
                process.Start(); // Start Onscreen Keyboard
                process.WaitForInputIdle();
                Win32.SetWindowPos((int)process.MainWindowHandle,
                Win32.HWND_BOTTOM,
                300, 300, 1200, 600,
                Win32.SWP_SHOWWINDOW | Win32.SWP_NOZORDER);
    
    
            }
    
    
    
        }
    }
    

    我有一个很好的键盘(适合触摸屏),但是我对C和VB一点都不熟悉。。。。根据我显示的触摸屏键盘更改文本框中的文本。

    谢谢,

    2 回复  |  直到 15 年前
        1
  •  2
  •   Community Mohan Dere    8 年前

    要创建自己的屏幕键盘,基本上需要执行以下操作。

    1-创建一个可以与之交互的windows键盘应用程序,但不会从当前控件中窃取输入焦点,当前控件中的每个应用程序都在其中工作。

    2-键盘应用程序应向当前活动控件发送按键,以响应键盘应用程序中按钮的点击。

    C# - Sending keyboard events to (last) selected window

    WS_EX_NOACTIVATE 样式,该样式可防止窗口成为活动窗口并调整输入焦点。然后响应按钮点击它使用 SendKeys 向具有输入焦点的控件发送适当的按键信息。

    下面的答案显示了如何应用 样式到WPF应用程序。

    Trying to create a WPF Touch Screen Keyboard Appliaction, Can't get WPF App to Send Keys to another window? Any suggestions?

        2
  •  1
  •   BVernon    12 年前

    +我只是因为我需要一个能从我的应用程序中更直接地控制它的代码。