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,17 @@ 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 ) )
15
- return false ;
14
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
15
+ return IsAnyWindowsScreenReaderEnabled ( ) ; // Check for macOS VoiceOver
16
16
17
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
18
+ return IsVoiceOverEnabled ( ) ;
19
+
20
+ // TODO: Support Linux per https://code.visualstudio.com/docs/configure/accessibility/accessibility
21
+ return false ;
22
+ }
23
+
24
+ private static bool IsAnyWindowsScreenReaderEnabled ( ) {
17
25
// The supposedly official way to check for a screen reader on
18
26
// Windows is SystemParametersInfo(SPI_GETSCREENREADER, ...) but it
19
27
// doesn't detect the in-box Windows Narrator and is otherwise known
@@ -48,5 +56,38 @@ internal static bool IsScreenReaderActive()
48
56
49
57
return false ;
50
58
}
59
+
60
+ private static bool IsVoiceOverEnabled ( )
61
+ {
62
+ try
63
+ {
64
+ // Use the 'defaults' command to check if VoiceOver is enabled
65
+ // This checks the com.apple.universalaccess preference for voiceOverOnOffKey
66
+ ProcessStartInfo startInfo = new ( )
67
+ {
68
+ FileName = "defaults" ,
69
+ Arguments = "read com.apple.universalaccess voiceOverOnOffKey" ,
70
+ UseShellExecute = false ,
71
+ RedirectStandardOutput = true ,
72
+ RedirectStandardError = true ,
73
+ CreateNoWindow = true
74
+ } ;
75
+
76
+ using Process process = Process . Start ( startInfo ) ;
77
+ process . WaitForExit ( 250 ) ;
78
+ if ( process . ExitCode == 0 )
79
+ {
80
+ string output = process . StandardOutput . ReadToEnd ( ) . Trim ( ) ;
81
+ // VoiceOver is enabled if the value is 1
82
+ return output == "1" ;
83
+ }
84
+ }
85
+ catch
86
+ {
87
+ // If we can't determine the status, assume VoiceOver is not enabled
88
+ }
89
+
90
+ return false ;
91
+ }
51
92
}
52
93
}
0 commit comments