@@ -10,15 +10,43 @@ internal class Accessibility
10
10
{
11
11
internal static bool IsScreenReaderActive ( )
12
12
{
13
- bool returnValue = false ;
13
+ // TODO: Support other platforms per https://code.visualstudio.com/docs/configure/accessibility/accessibility
14
+ if ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
15
+ return false ;
14
16
15
- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
17
+ // The supposedly official way to check for a screen reader on
18
+ // Windows is SystemParametersInfo(SPI_GETSCREENREADER, ...) but it
19
+ // doesn't detect the in-box Windows Narrator and is otherwise known
20
+ // to be problematic.
21
+ //
22
+ // The following is adapted from the Electron project, under the MIT License.
23
+ // Hence this is also how VS Code detects screenreaders.
24
+ // See: https://github.com/electron/electron/pull/39988
25
+
26
+ // Check for Windows Narrator using the NarratorRunning mutex
27
+ if ( PlatformWindows . IsMutexPresent ( "NarratorRunning" ) )
28
+ return true ;
29
+
30
+ // Check for various screen reader libraries
31
+ string [ ] screenReaderLibraries = {
32
+ // NVDA
33
+ "nvdaHelperRemote.dll" ,
34
+ // JAWS
35
+ "jhook.dll" ,
36
+ // Window-Eyes
37
+ "gwhk64.dll" ,
38
+ "gwmhook.dll" ,
39
+ // ZoomText
40
+ "AiSquared.Infuser.HookLib.dll"
41
+ } ;
42
+
43
+ foreach ( string library in screenReaderLibraries )
16
44
{
17
- // NOTE: This API can detect if a third-party screen reader is active, such as NVDA, but not the in-box Windows Narrator.
18
- PlatformWindows . SystemParametersInfo ( PlatformWindows . SPI_GETSCREENREADER , 0 , ref returnValue , 0 ) ;
19
- } // TODO: Support other platforms per https://code.visualstudio.com/docs/configure/accessibility/accessibility
45
+ if ( PlatformWindows . IsLibraryLoaded ( library ) )
46
+ return true ;
47
+ }
20
48
21
- return returnValue ;
49
+ return false ;
22
50
}
23
51
}
24
52
}
0 commit comments