Programmatically Detecting Screen Readers

I was installing the RC of Visual Studio 2010 yesterday and while the setup program ran I noticed the words CHECKED and UNCHECKED appearing in the Tree View.
I was thinking I'd found some cool bug, like I was peering into some background world where checkboxes announce their state with text or something. I dunno, it was late, don't judge! ;)
I asked a few people and someone said to to see if I was running a Screen Reader. Screen Readers are what the visually impaired use to find their way around interfaces. It's no at bug at all, it's helping me.
I ran a little program based on this chunk of code found here. I started using the structures found at PInvoke.NET but they were overkill. I didn't need six pages of constants.
[DllImport("user32.dll")]
static extern bool SystemParametersInfo(int iAction, int iParam, out bool bActive, int iUpdate);
public static bool IsScreenReaderActive()
{
int iAction = 70; // SPI_GETSCREENREADER constant;
int iParam = 0;
int iUpdate = 0;
bool bActive = false;
bool bReturn = SystemParametersInfo(iAction, iParam, out bActive, iUpdate);
return bReturn && bActive;
}
static void Main(string[] args)
{
bool retVal = IsScreenReaderActive();
}
Scandalously, the result was true. What? I am running a screen reader? Um, no.
Well, actually, yes. I give lots of presentations, sometimes just to one person looking over my shoulder so I run the Windows 7 Magnifier via the WinKey and PLUS hotkey. When the Windows Magnifier is running, I'm running a Screen Reader in that I'm running an accessibility assistant.
Interesting stuff. I like it when applications are paying attention and helping with accessibility.
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
About Newsletter


Here's an outline of what Deployment Related topics I tried to cover


