Overlay, winhooks: add screen reader detection to prevent the setting of winhooks if a screen reader was found to be running at app startup

This commit is contained in:
Ethin Probst 2019-11-14 14:37:07 -06:00 committed by Robert Adam
parent 2004de970c
commit a310c7fa20
2 changed files with 30 additions and 1 deletions

View File

@ -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"
@ -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);
@ -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;
}

View File

@ -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 &);