2010-07-03 134 views
2

我一直在研究触摸屏应用程序。我需要知道是否有现成的触摸屏键盘可以用作我的应用程序的控制器。触摸屏键盘

我尝试使用Windows准备键盘,但它对于触摸屏来说太小了。

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); 


     } 



    } 
} 

这工作得很好我有一个漂亮的小键盘(触摸屏的大小很好),但是,我不熟悉w ith C#和VB在所有....根据我显示的触摸屏键盘更改文本框中的文本。

感谢,

回答

2

要创建自己的屏幕键盘上你基本上需要做到以下几点。

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

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

我以前提供的以下答案提供了如何使用WinForms执行此操作的简单演示。

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

基本上与WS_EX_NOACTIVATE样式,这防止了窗口从becomming活性和钢化输入焦点创建的窗口。然后,响应按钮单击,它使用SendKeys将适当的按键消息发送到具有输入焦点的控件。

以下答案显示了如何将WS_EX_NOACTIVATE样式应用于WPF应用程序。

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

还有比WS_EX_NOACTIVATE等其他解决方案,但这种简单,以防万一拖动窗口时,只能从一个小故障表象遭遇。哪些具有一些聪明的消息处理可以被克服。

+0

感谢克里斯,我用一个工作代码编辑我的问题,除了我不知道我将如何提取键盘敲击并使它们显示在文本框中。 谢谢 – 2010-07-03 10:49:54

+0

没关系!我解决了这个问题....我只是把重点放在文本框上!抱歉!谢谢 – 2010-07-03 11:31:06

1

我知道这真的很老,但为了防止别人的第一个想法是屏幕键盘上的Windows内置过小(这也是我的第一个想法),事实上可以使它更大通过使窗口更大(你也可以通过编程)。

+1的问题和发布的代码,但因为我只是因为我需要一个更直接控制它从我的应用程序。

+0

我会给你+1的答案。我没有看到我的问题,虽然:( – 2014-01-28 18:25:18

+0

哈哈,我意外地离开之前,我做到了。你去...现在只有3更多到2000 :) – BVernon 2014-01-29 06:46:38