2010-07-03 120 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