Skip to content

Commit 527fa6a

Browse files
SteveL-MSFTdaxian-dbw
authored andcommitted
Add API to detect if the screen reader is active (#947)
1 parent f2f5531 commit 527fa6a

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

PSReadLine/Accessibility.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/********************************************************************++
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
--********************************************************************/
4+
5+
using System.Runtime.InteropServices;
6+
7+
namespace Microsoft.PowerShell.Internal
8+
{
9+
internal class Accessibility
10+
{
11+
internal static bool IsScreenReaderActive()
12+
{
13+
bool returnValue = false;
14+
15+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
16+
{
17+
PlatformWindows.SystemParametersInfo(PlatformWindows.SPI_GETSCREENREADER, 0, ref returnValue, 0);
18+
}
19+
20+
return returnValue;
21+
}
22+
}
23+
}

PSReadLine/PlatformWindows.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,4 +604,10 @@ public override void BlankRestOfLine()
604604
SetCursorPosition(x, y);
605605
}
606606
}
607+
608+
internal const uint SPI_GETSCREENREADER = 0x0046;
609+
610+
[DllImport("user32.dll", SetLastError = true)]
611+
[return: MarshalAs(UnmanagedType.Bool)]
612+
internal static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref bool pvParam, uint fWinIni);
607613
}

0 commit comments

Comments
 (0)