WinHide not working properly.

Issue #86 closed
Winter Laite created an issue

This script should run without modification i both AHK2 and Keysharp.

SetTitleMatchMode(2)
DetectHiddenWindows(True)

Run("notepad.exe")
Sleep(2000)
WinHide("Untitled - Notepad ahk_class Notepad")
Sleep(2000)
WinShow("Untitled - Notepad ahk_class Notepad")
Sleep(1000)
WinKill("Untitled - Notepad ahk_class Notepad")
ExitApp()

With AHK it shows Notepad for 2 seconds, hides Notepad for 2 seconds, shows Notepad for 1 second, then exits.

When run from Keysharp this error message is generated.

Uncaught exception: 
Message: Object reference not set to an instance of an object. 
Stack:    at Keysharp.Core.Common.Window.SearchCriteria.FromString(Object obj) in C:\Users\testuser\Documents\repos\keysharp\Keysharp.Core\Common\Window\SearchCriteria.cs:line 57 
at Keysharp.Core.Common.Window.SearchCriteria.FromString(Object title, String text, String excludeTitle, String excludeText) in C:\Users\testuser\Documents\repos\keysharp\Keysharp.Core\Common\Window\SearchCriteria.cs:line 121 
at Keysharp.Core.Common.Window.WindowManagerBase.FindWindowGroup(Object title, String text, String excludeTitle, String excludeText, Boolean forceAll) in C:\Users\testuser\Documents\repos\keysharp\Keysharp.Core\Common\Window\WindowManagerBase.cs:line 72 
at Keysharp.Core.Window.SearchWindows(Object[] obj) in C:\Users\testuser\Documents\repos\keysharp\Keysharp.Core\Core\Gui\Window.cs:line 994 
c__DisplayClass85_0.<WinHide>b__0() in C:\Users\testuser\Documents\repos\keysharp\Keysharp.Core\Core\Gui\Window.cs:line 593 
at Keysharp.Core.Window.DoDelayedAction(Action act) in C:\Users\testuser\Documents\repos\keysharp\Keysharp.Core\Core\Gui\Window.cs:line 888 
at Keysharp.Core.Window.WinHide(Object[] obj) in C:\Users\testuser\Documents\repos\keysharp\Keysharp.Core\Core\Gui\Window.cs:line 593 
at Keysharp.CompiledMain.Program.Main(String[] args) 

Comments (5)

  1. Winter Laite reporter

    This code is closer to the example on the docs page, and also fails with the same error message:

    Run("notepad.exe")
    WinWait("Untitled - Notepad")
    Sleep(500)
    WinHide() ; Use the window found by WinWait.
    Sleep(1000)
    WinShow() ; Use the window found by WinWait.
    ExitApp()
    

  2. Log in to comment