【发布时间】:2015-03-27 00:06:11
【问题描述】:
Windows 8 中是否有办法检测虚拟键盘是否在屏幕上可见?我使用 tabtip.exe
【问题讨论】:
Windows 8 中是否有办法检测虚拟键盘是否在屏幕上可见?我使用 tabtip.exe
【问题讨论】:
在 google 上进行简短搜索后,我可以做一些可能对您有所帮助的事情。下面的代码公开了 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
}
【讨论】: