Is there a way in Windows 8 to detect if the virtual keyboard is visible on screen? I use tabtip.exe
After a brief search on google , I could do something that might help you. The code below exposes a function of the windows API and uses it to know the current state of a given process. Understand state as Minimized , Maximized, Hidden or Normal.
The ProccesIsRunningNotMinimized method returns true if the program is running and is not minimized or hidden.
I do not know if this will help you, but it's a start .
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,
}
To check if the VK is running and visible in the screen, do:
if (this.ProccesIsRunningNotMinimized("tabtip"))
{
// do something
}
此代码在Windows 7上运行良好。在Windows 8上将无法使用。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.