Windows 8中是否有办法检测虚拟键盘是否在屏幕上可见?我使用tabtip.exe
答案 0 :(得分:0)
在谷歌上进行短暂搜索后,我可以做一些可能对你有帮助的事情。下面的代码公开了Windows API的一个功能,并使用它来了解给定进程的当前状态。将状态理解为最小化,最大化,隐藏或正常。
如果程序正在运行且未最小化或隐藏,则ProccesIsRunningNotMinimized方法返回true。
我不知道这对你有帮助,但这是一个开始。
public bool ProccesIsRunningNotMinimized(string exeName)
{
Process[] processes = Process.GetProcesses();
foreach (Process p in processes)
{
if (p.ProcessName.ToLower() == exeName.ToLower())
{
var placement = GetPlacement(p.MainWindowHandle);
if (placement.showCmd.ToString().ToLower() != "minimized" && placement.showCmd.ToString().ToLower() != "hide")
return true;
}
}
return false;
}
// Get the placement of the target process
private static WINDOWPLACEMENT GetPlacement(IntPtr hwnd)
{
WINDOWPLACEMENT placement = new WINDOWPLACEMENT();
placement.length = Marshal.SizeOf(placement);
GetWindowPlacement(hwnd, ref placement);
return placement;
}
//Exposes the function of Windows API
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool GetWindowPlacement(
IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
//Create a struct to receive the data
[Serializable]
[StructLayout(LayoutKind.Sequential)]
internal struct WINDOWPLACEMENT
{
public int length;
public int flags;
public ShowWindowCommands showCmd;
public System.Drawing.Point ptMinPosition;
public System.Drawing.Point ptMaxPosition;
public System.Drawing.Rectangle rcNormalPosition;
}
internal enum ShowWindowCommands : int
{
Hide = 0,
Normal = 1,
Minimized = 2,
Maximized = 3,
}
要检查VK是否在屏幕上运行且可见,请执行以下操作:
if (this.ProccesIsRunningNotMinimized("tabtip"))
{
// do something
}
答案 1 :(得分:0)
此代码在Windows 7上运行正常。在Windows 8上无效。