2
2
Copyright (c) Microsoft Corporation. All rights reserved.
3
3
--********************************************************************/
4
4
5
+ using System . Diagnostics ;
5
6
using System . Runtime . InteropServices ;
6
7
7
8
namespace Microsoft . PowerShell . Internal
@@ -10,10 +11,22 @@ internal class Accessibility
10
11
{
11
12
internal static bool IsScreenReaderActive ( )
12
13
{
13
- // TODO: Support other platforms per https://code.visualstudio.com/docs/configure/accessibility/accessibility
14
- if ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
14
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
15
+ {
16
+ return IsAnyWindowsScreenReaderEnabled ( ) ;
17
+ }
18
+
19
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
20
+ {
21
+ return IsVoiceOverEnabled ( ) ;
22
+ }
23
+
24
+ // TODO: Support Linux per https://code.visualstudio.com/docs/configure/accessibility/accessibility
15
25
return false ;
26
+ }
16
27
28
+ private static bool IsAnyWindowsScreenReaderEnabled ( )
29
+ {
17
30
// The supposedly official way to check for a screen reader on
18
31
// Windows is SystemParametersInfo(SPI_GETSCREENREADER, ...) but it
19
32
// doesn't detect the in-box Windows Narrator and is otherwise known
@@ -48,5 +61,38 @@ internal static bool IsScreenReaderActive()
48
61
49
62
return false ;
50
63
}
64
+
65
+ private static bool IsVoiceOverEnabled ( )
66
+ {
67
+ try
68
+ {
69
+ // Use the 'defaults' command to check if VoiceOver is enabled
70
+ // This checks the com.apple.universalaccess preference for voiceOverOnOffKey
71
+ ProcessStartInfo startInfo = new ( )
72
+ {
73
+ FileName = "defaults" ,
74
+ Arguments = "read com.apple.universalaccess voiceOverOnOffKey" ,
75
+ UseShellExecute = false ,
76
+ RedirectStandardOutput = true ,
77
+ RedirectStandardError = true ,
78
+ CreateNoWindow = true
79
+ } ;
80
+
81
+ using Process process = Process . Start ( startInfo ) ;
82
+ process . WaitForExit ( 250 ) ;
83
+ if ( process . HasExited && process . ExitCode == 0 )
84
+ {
85
+ string output = process . StandardOutput . ReadToEnd ( ) . Trim ( ) ;
86
+ // VoiceOver is enabled if the value is 1
87
+ return output == "1" ;
88
+ }
89
+ }
90
+ catch
91
+ {
92
+ // If we can't determine the status, assume VoiceOver is not enabled
93
+ }
94
+
95
+ return false ;
96
+ }
51
97
}
52
98
}
0 commit comments