So I'm currently trying to check if a user is using a screen reader on our site. The reason I would like to check if they are is because our site provides a training module in which if they are using a screen reader, I would like to show a button that would allow them to download a printable version of the training.
Here is what I have tried so far:
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;
}
}
}
I snagged this code from the following StackOverflow thread: C# : How to detect if screen reader is running?
The method I'm using apparently works for some as you can see on this thread, but I'm currently always getting "false" when calling ScreenReader.IsRunning. I'm storing the ScreenReader.IsRunning value in a ViewBag and then in my view I'm using razor syntax to show a button if that value is true. Not really sure why its always false. I have tested this using JAWS as well as Narrator that comes on everyone's computer if you are using Windows 10 I think. Any help would be much appreciated. Thank you all!