Skip to content

Commit

Permalink
Overlay, winhooks: add screen reader detection to prevent the setting…
Browse files Browse the repository at this point in the history
… of winhooks if a screen reader was found to be running at app startup
  • Loading branch information
ethindp authored and Krzmbrzl committed Jan 20, 2020
1 parent 2004de9 commit a310c7f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/mumble/GlobalShortcut_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
// 3rdparty/xinputcheck-src.
#include <xinputcheck.h>

// Used to detect screen readers
#include <tlhelp32.h>

// We define a global macro called 'g'. This can lead to issues when included code uses 'g' as a type or parameter name (like protobuf 3.7 does). As such, for now, we have to make this our last include.
#include "Global.h"

Expand Down Expand Up @@ -129,7 +132,8 @@ GlobalShortcutWin::GlobalShortcutWin()
#endif
{
// Hidden setting to disable hooking
bHook = g.qs->value(QLatin1String("winhooks"), true).toBool();
// Also disable hooking if a screen reader is running
bHook = g.qs->value(QLatin1String("winhooks"), true).toBool() && !areScreenReadersActive();

moveToThread(this);
start(QThread::LowestPriority);
Expand Down Expand Up @@ -899,3 +903,25 @@ QString GlobalShortcutWin::buttonName(const QVariant &v) {
bool GlobalShortcutWin::canSuppress() {
return bHook;
}

bool GlobalShortcutWin::areScreenReadersActive() {
// This list contains valid executables we consider to be 'screen readers'.
// Todo: perhaps make this a configuration option in mumble to let users dynamically add executables.
const QStringList executables = { QLatin1String("nvda.exe"), QLatin1String("jfw.exe") };

const auto snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (snapshot != INVALID_HANDLE_VALUE) {
PROCESSENTRY32 p;
p.dwSize = sizeof(p);
auto ok = Process32First(snapshot, &p);
while (ok) {
if (executables.contains(QString::fromWCharArray(p.szExeFile))) {
CloseHandle(snapshot);
return true;
}
ok = Process32Next(snapshot, &p);
}
CloseHandle(snapshot);
}
return false;
}
3 changes: 3 additions & 0 deletions src/mumble/GlobalShortcut_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ class GlobalShortcutWin : public GlobalShortcutEngine {
/// @return Returns true if the GlobalShortcut engine signalled that
/// the button should be suppressed. Returns false otherwise.
bool injectMouseMessage(MSG *msg);

private:
bool areScreenReadersActive();
};

uint qHash(const GUID &);
Expand Down

0 comments on commit a310c7f

Please sign in to comment.