1

Is there a way in Windows 8 to detect if the virtual keyboard is visible on screen? I use tabtip.exe

WymyslonyNick
  • 117
  • 3
  • 19

2 Answers2

0

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
}
0

This code works fine on Windows 7. On windows 8 will not work.

WymyslonyNick
  • 117
  • 3
  • 19
  • Try with `GetWindowLong` instead of `GetWindowPlacement` like [this](http://stackoverflow.com/a/11065126/122195). Also try with [IsIconic](https://msdn.microsoft.com/en-us/library/windows/desktop/ms633527(v=vs.85).aspx) that determines whether the specified window is minimized. – thepirat000 Mar 26 '15 at 16:29
  • I tested the code with no windows 8.1. It worked perfectly. Very weird – João Luiz Grigoletti Mar 26 '15 at 19:22
  • You can check on tabtip.exe process (becouse tabtip runs in a specific way)? – WymyslonyNick Mar 26 '15 at 19:43
  • I changed nothing and only works on Windows 7. Could you send me the .zip project? – WymyslonyNick Mar 26 '15 at 20:55