C#:如何检测屏幕阅读器是否正在运行?

发布于 2024-12-14 20:54:18 字数 342 浏览 3 评论 0原文

如何检测屏幕阅读器是否正在运行(JAWS)?

据我了解,在 .NET 4 中,我们可以使用 System.Windows.Automation.Provider 命名空间中的 AutomationInteropProvider.ClientsAreListening ,但是如果我必须在 .NET 2.0 中这样做怎么办?

我尝试检查 ClientsAreListening 源代码,它从 UIAutomationCore.dll 库调用外部 RawUiaClientsAreListening 方法。

您对如何在 .NET 2.0 中实现 JAWS 检测有什么想法吗?

How to detect if screen reader is running (JAWS)?

As I understand in .NET 4 we can use AutomationInteropProvider.ClientsAreListening from System.Windows.Automation.Provider namespace, but what if I have to do it for .NET 2.0?

I tried to inspect ClientsAreListening source code, it calls external RawUiaClientsAreListening method from UIAutomationCore.dll library.

Do you have any ideas how to implement JAWS detection in .NET 2.0?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小情绪 2024-12-21 20:54:18

使用 SystemParametersInfo 函数< /a> 传递 SPI_GETSCREENREADERuiAction

您需要为此使用 P/Invoke ,例如:

internal class UnsafeNativeMethods
{
    public const uint SPI_GETSCREENREADER = 0x0046;

    [DllImport("user32.dll", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref bool pvParam, uint fWinIni);
}

public static class ScreenReader
{
    public static bool IsRunning
    {
        get
        {
            bool returnValue = false;
            if (!UnsafeNativeMethods.SystemParametersInfo(UnsafeNativeMethods.SPI_GETSCREENREADER, 0, ref returnValue, 0))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "error calling SystemParametersInfo");
            }
            return returnValue;
        }
    }
}

这可能更好比使用 ClientsAreListening 属性,因为此属性似乎对任何自动化客户端(而不仅仅是屏幕阅读器)返回 true。

另请参阅:

您还应该侦听 WM_SETTINGCHANGE 消息以检测屏幕阅读器是否启动/停止跑步。


更新(回应 BrendanMcK 的评论):

虽然从未用如此多的文字明确记录这一点,但查看该标志的描述我认为该标志的目的相对明确:

确定屏幕查看器实用程序是否正在运行。屏幕查看器实用程序将文本信息定向到输出设备,例如语音合成器或盲文显示器。设置此标志后,应用程序应在以图形方式显示信息的情况下提供文本信息。

这意味着,每当应用程序希望 UI 表现得像屏幕阅读器正在运行时,应用程序就会设置此标志,无论该应用程序是否实际上是屏幕阅读器。

响应此标志的合适操作是 添加文本以便向用户“读取”直观的 UI 状态。如果需要彻底更改来使您的 UI 屏幕阅读器易于访问,那么您的 UI 对于签名用户来说也可能不是那么直观,可能需要重新考虑。

Use the SystemParametersInfo function passing a uiAction of SPI_GETSCREENREADER.

You will need to use P/Invoke for this, for example:

internal class UnsafeNativeMethods
{
    public const uint SPI_GETSCREENREADER = 0x0046;

    [DllImport("user32.dll", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref bool pvParam, uint fWinIni);
}

public static class ScreenReader
{
    public static bool IsRunning
    {
        get
        {
            bool returnValue = false;
            if (!UnsafeNativeMethods.SystemParametersInfo(UnsafeNativeMethods.SPI_GETSCREENREADER, 0, ref returnValue, 0))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "error calling SystemParametersInfo");
            }
            return returnValue;
        }
    }
}

This is possibly better than using the ClientsAreListening property as this property appears to return true for any automation client, not just screen readers.

Also see:

You should also listen for the WM_SETTINGCHANGE message to detect if a screen reader starts / stops running.


Update (in response to BrendanMcK's comments):

Although this is never explicitly documented in as many words, looking at the description of the flag I think the purpose of this flag is relatively clear:

Determines whether a screen reviewer utility is running. A screen reviewer utility directs textual information to an output device, such as a speech synthesizer or Braille display. When this flag is set, an application should provide textual information in situations where it would otherwise present the information graphically.

What this is saying is that applications set this flag whenever an application wishes the UI to behave as if a screen reader is running, regardless of whether or not that application is actually a screen reader or not.

Suitable things to do in response to this flag is to add text in order to "read" otherwise intuitive UI state to the user. If radical changes are needed to make your UI screen reader accessible then the chances are that your UI also isn't that intuitive to sigted users and could probably do with a re-think.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文