![](/img/trans.png)
[英]Virtual Keyboard (Swype like Keyboard) Windows Forms Application C#
[英]c# Windows 10 virtual keyboard issues
我已經開發了ac#代碼段,以確定是否顯示了虛擬(屏幕上)鍵盤。
下面的代碼在Windows 7、8和8.1中工作正常,但是在Windows 10中, IsKeyboardVisible
始終返回true
...
public static bool IsKeyboardVisible() {
Process keyboardProc;
UInt32 WS_DISABLED = 0x8000000;
UInt32 WS_VISIBLE = 0X94000000;
int GWL_STYLE = -16;
IntPtr keyboardHandle = GetKeyboardWindowHandle();
bool visible = false;
if (keyboardHandle != IntPtr.Zero) {
UInt32 style = GetWindowLong(keyboardHandle, GWL_STYLE);
// in Win10, this always returns "true", i.e. WS_DISABLED is
//
//visible = ((style & WS_DISABLED) != WS_DISABLED);
// UPDATE: I found this code helping here
visible = (style == WS_VISIBLE);
}
return visible;
}
我使用了關於SO的教程,但是前一陣子很抱歉,我不相信作者。
有誰知道所有最新Windows版本的工作代碼段,因此我不必檢查實際的操作系統即可打開該版本...?
更新
我在這里找到了原始帖子 ,這使我可以更正代碼。 所以現在我的問題是相同的舊Win10問題-我無法使用
string progFiles = @"C:\Program Files\Common Files\Microsoft Shared\ink";
string keyboardPath = Path.Combine(progFiles, "TabTip.exe");
keyboardProc = Process.Start(keyboardPath);
...同樣,我可以使用任何“全平台”代碼,或者Win10的建議方法是什么?
更新2我發現有關在64位操作系統上運行32位應用程序的問題。 話雖如此,無論我嘗試在System32
還是sysWOW64`文件夾中運行osk.exe
,都會發生錯誤...除了制作64位版本之外,還有其他方法嗎???
在深入研究TabTip.exe
, osk.exe
以及x86和x64兼容性問題之后,我找到了一個解決方案,方法是在系統上搜索osk.exe
並嘗試運行它們。 我在以下文件夾中找到了4版本:
C:\\Windows\\System32
C:\\Windows\\SysWOW64
C:\\Windows\\WinSxS\\amd64_microsoft...
C:\\Windows\\WinSxS\\wow64_microsoft...
似乎在C:\\Windows\\WinSxS\\amd64_microsoft...
工作正常(盡管不是其他三個)...
鑒於“ amd64 _....”文件夾在不同的計算機上可能不相同(我實際上檢查了它們,但它們不匹配,因此我沒有搜索這是否取決於計算機,Windows構建或其他任何內容... )。
因此,基本上,我做了一個小例程來查看WinSxS
文件夾並返回osk.exe
出現,效果很好。 我還使用簡單的OS體系結構測試使代碼在32位OS上工作:
string OSKpath64 = getOskPath(@"C:\Windows\WinSxS");
if (string.IsNullOrWhiteSpace(OSKpath64)) {
OSKpath64 = "osk.exe";
}
string OSKpath32 = @"C:\Windows\System32\osk.exe";
if (!File.Exists(OSKpath32)) {
OSKpath32 = @"osk.exe";
}
System.Diagnostics.Process.Start((Environment.Is64BitOperatingSystem) ? OSKpath64 : OSKpath32);
更新: WinSxS
文件夾中對一個可用版本和一個不可用版本的困惑使我感到緊張。 由於amd_..
文件夾按字母順序在wow64_...
之前, wow64_...
它可以正常工作。
因此,我建議在getOskPath
方法中添加一個測試以返回第一個本機64位osk.exe
(而不是模擬的)。
使用此處找到的IsWin64Emulator
方法 ,該方法如下所示:
static string getOskPath(string dir) {
string path = Path.Combine(dir, "osk.exe");
if (File.Exists(path)) {
Process p = System.Diagnostics.Process.Start(path);
if (p.IsWin64Emulator()) {
path = string.Empty;
}
p.Kill();
return path;
}
DirectoryInfo di = new DirectoryInfo(dir);
foreach (DirectoryInfo subDir in di.GetDirectories().Reverse()) {
path = getOskPath(Path.Combine(dir, subDir.Name));
if (!string.IsNullOrWhiteSpace(path)) {
return path;
}
}
return string.Empty;
}
我遇到了同樣的問題,我在這里嘗試所有答案,但是沒有用。 用Google找到解決方案后,就可以了。
// Step 1: For Load On-Screen Keyboard
const string Kernel32dll = "Kernel32.Dll";
[DllImport(Kernel32dll, EntryPoint = "Wow64DisableWow64FsRedirection")]
public static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);
[DllImport(Kernel32dll, EntryPoint = "Wow64EnableWow64FsRedirection")]
public static extern bool Wow64EnableWow64FsRedirection(IntPtr ptr);
IntPtr wow64Value;
//---------------------------------------
// Step 2: Function-----
if (Environment.Is64BitOperatingSystem)
{
if (Wow64DisableWow64FsRedirection(ref wow64Value))
{
System.Diagnostics.Process.Start("osk.exe");
Wow64EnableWow64FsRedirection(wow64Value);
}
}
else
{
System.Diagnostics.Process.Start("osk.exe");
}
//----------------
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.