mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
[KBM]Send remappings configuration telemetry (#31563)
* [KBM]Send remappings configuration telemetry * Add comments for the index comparisons
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "pch.h"
|
||||
#include "trace.h"
|
||||
#include <common/interop/keyboard_layout.h>
|
||||
|
||||
TRACELOGGING_DEFINE_PROVIDER(
|
||||
g_hProvider,
|
||||
@@ -82,6 +83,181 @@ void Trace::ShortcutRemapInvoked(bool isShortcutToShortcut, bool isAppSpecific)
|
||||
}
|
||||
}
|
||||
|
||||
// Function to return a human readable string for the shortcut
|
||||
std::wstring GetShortcutHumanReadableString(Shortcut const & shortcut, LayoutMap& keyboardMap)
|
||||
{
|
||||
std::wstring humanReadableShortcut = L"";
|
||||
if (shortcut.winKey != ModifierKey::Disabled)
|
||||
{
|
||||
humanReadableShortcut += keyboardMap.GetKeyName(shortcut.GetWinKey(ModifierKey::Both)) + L" + ";
|
||||
}
|
||||
if (shortcut.ctrlKey != ModifierKey::Disabled)
|
||||
{
|
||||
humanReadableShortcut += keyboardMap.GetKeyName(shortcut.GetCtrlKey()) + L" + ";
|
||||
}
|
||||
if (shortcut.altKey != ModifierKey::Disabled)
|
||||
{
|
||||
humanReadableShortcut += keyboardMap.GetKeyName(shortcut.GetAltKey()) + L" + ";
|
||||
}
|
||||
if (shortcut.shiftKey != ModifierKey::Disabled)
|
||||
{
|
||||
humanReadableShortcut += keyboardMap.GetKeyName(shortcut.GetShiftKey()) + L" + ";
|
||||
}
|
||||
if (shortcut.actionKey != NULL)
|
||||
{
|
||||
humanReadableShortcut += keyboardMap.GetKeyName(shortcut.actionKey);
|
||||
}
|
||||
return humanReadableShortcut;
|
||||
}
|
||||
|
||||
|
||||
// Log the current remappings of key and shortcuts when keyboard manager engine loads the settings.
|
||||
void Trace::SendKeyAndShortcutRemapLoadedConfiguration(State& remappings) noexcept
|
||||
{
|
||||
LayoutMap keyboardMap;
|
||||
for (auto const& keyRemap : remappings.singleKeyReMap)
|
||||
{
|
||||
if (keyRemap.second.index() == 0) // 0 - Remapping to key
|
||||
{
|
||||
DWORD keyRemappedTo = std::get<DWORD>(keyRemap.second);
|
||||
TraceLoggingWrite(
|
||||
g_hProvider,
|
||||
"KeyboardManager_KeyRemapConfigurationLoaded",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingInt64(keyRemap.first, "KeyRemapFrom"),
|
||||
TraceLoggingInt64(keyRemappedTo, "KeyRemapTo"),
|
||||
TraceLoggingWideString(keyboardMap.GetKeyName(keyRemap.first).c_str(), "HumanRemapFrom"),
|
||||
TraceLoggingWideString(keyboardMap.GetKeyName(keyRemappedTo).c_str(), "HumanRemapTo")
|
||||
);
|
||||
}
|
||||
else if (keyRemap.second.index() == 1) // 1 - Remapping to shortcut
|
||||
{
|
||||
Shortcut shortcutRemappedTo = std::get<Shortcut>(keyRemap.second);
|
||||
TraceLoggingWrite(
|
||||
g_hProvider,
|
||||
"KeyboardManager_KeyRemapConfigurationLoaded",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingInt64(keyRemap.first, "KeyRemapFrom"),
|
||||
TraceLoggingInt64(shortcutRemappedTo.actionKey, "KeyRemapTo"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedTo.winKey), "ModifierRemapToWin"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedTo.ctrlKey), "ModifierRemapToCtrl"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedTo.altKey), "ModifierRemapToAlt"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedTo.shiftKey), "ModifierRemapToShift"),
|
||||
TraceLoggingWideString(keyboardMap.GetKeyName(keyRemap.first).c_str(), "HumanRemapFrom"),
|
||||
TraceLoggingWideString(GetShortcutHumanReadableString(shortcutRemappedTo, keyboardMap).c_str(), "HumanRemapTo")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto const& shortcutRemap : remappings.osLevelShortcutReMap)
|
||||
{
|
||||
Shortcut shortcutRemappedFrom = shortcutRemap.first;
|
||||
if (shortcutRemap.second.targetShortcut.index() == 0) // 0 - Remapping to key
|
||||
{
|
||||
DWORD keyRemappedTo = std::get<DWORD>(shortcutRemap.second.targetShortcut);
|
||||
TraceLoggingWrite(
|
||||
g_hProvider,
|
||||
"KeyboardManager_ShortcutRemapConfigurationLoaded",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingInt64(shortcutRemappedFrom.actionKey, "KeyRemapFrom"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedFrom.winKey), "ModifierRemapFromWin"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedFrom.ctrlKey), "ModifierRemapFromCtrl"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedFrom.altKey), "ModifierRemapFromAlt"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedFrom.shiftKey), "ModifierRemapFromShift"),
|
||||
TraceLoggingInt64(keyRemappedTo, "KeyRemapTo"),
|
||||
TraceLoggingWideString(GetShortcutHumanReadableString(shortcutRemappedFrom, keyboardMap).c_str(), "HumanRemapFrom"),
|
||||
TraceLoggingWideString(keyboardMap.GetKeyName(keyRemappedTo).c_str(), "HumanRemapTo"));
|
||||
}
|
||||
else if (shortcutRemap.second.targetShortcut.index() == 1) // 1 - Remapping to shortcut
|
||||
{
|
||||
Shortcut shortcutRemappedTo = std::get<Shortcut>(shortcutRemap.second.targetShortcut);
|
||||
TraceLoggingWrite(
|
||||
g_hProvider,
|
||||
"KeyboardManager_ShortcutRemapConfigurationLoaded",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingInt64(shortcutRemappedFrom.actionKey, "KeyRemapFrom"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedFrom.winKey), "ModifierRemapFromWin"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedFrom.ctrlKey), "ModifierRemapFromCtrl"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedFrom.altKey), "ModifierRemapFromAlt"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedFrom.shiftKey), "ModifierRemapFromShift"),
|
||||
TraceLoggingInt64(shortcutRemappedTo.actionKey, "KeyRemapTo"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedTo.winKey), "ModifierRemapToWin"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedTo.ctrlKey), "ModifierRemapToCtrl"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedTo.altKey), "ModifierRemapToAlt"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedTo.shiftKey), "ModifierRemapToShift"),
|
||||
TraceLoggingWideString(GetShortcutHumanReadableString(shortcutRemappedFrom, keyboardMap).c_str(), "HumanRemapFrom"),
|
||||
TraceLoggingWideString(GetShortcutHumanReadableString(shortcutRemappedTo, keyboardMap).c_str(), "HumanRemapTo")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto const& appShortcutRemap : remappings.appSpecificShortcutReMap)
|
||||
{
|
||||
std::wstring appName = appShortcutRemap.first;
|
||||
for (auto const& shortcutRemap : appShortcutRemap.second)
|
||||
{
|
||||
Shortcut shortcutRemappedFrom = shortcutRemap.first;
|
||||
if (shortcutRemap.second.targetShortcut.index() == 0) // 0 - Remapping to key
|
||||
{
|
||||
DWORD keyRemappedTo = std::get<DWORD>(shortcutRemap.second.targetShortcut);
|
||||
TraceLoggingWrite(
|
||||
g_hProvider,
|
||||
"KeyboardManager_AppSpecificShortcutRemapConfigurationLoaded",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingInt64(shortcutRemappedFrom.actionKey, "KeyRemapFrom"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedFrom.winKey), "ModifierRemapFromWin"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedFrom.ctrlKey), "ModifierRemapFromCtrl"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedFrom.altKey), "ModifierRemapFromAlt"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedFrom.shiftKey), "ModifierRemapFromShift"),
|
||||
TraceLoggingInt64(keyRemappedTo, "KeyRemapTo"),
|
||||
TraceLoggingWideString(GetShortcutHumanReadableString(shortcutRemappedFrom, keyboardMap).c_str(), "HumanRemapFrom"),
|
||||
TraceLoggingWideString(keyboardMap.GetKeyName(keyRemappedTo).c_str(), "HumanRemapTo"),
|
||||
TraceLoggingWideString(appName.c_str(), "TargetApp")
|
||||
);
|
||||
}
|
||||
else if (shortcutRemap.second.targetShortcut.index() == 1) // 1 - Remapping to shortcut
|
||||
{
|
||||
Shortcut shortcutRemappedTo = std::get<Shortcut>(shortcutRemap.second.targetShortcut);
|
||||
TraceLoggingWrite(
|
||||
g_hProvider,
|
||||
"KeyboardManager_AppSpecificShortcutRemapConfigurationLoaded",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||
TraceLoggingInt64(shortcutRemappedFrom.actionKey, "KeyRemapFrom"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedFrom.winKey), "ModifierRemapFromWin"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedFrom.ctrlKey), "ModifierRemapFromCtrl"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedFrom.altKey), "ModifierRemapFromAlt"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedFrom.shiftKey), "ModifierRemapFromShift"),
|
||||
TraceLoggingInt64(shortcutRemappedTo.actionKey, "KeyRemapTo"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedTo.winKey), "ModifierRemapToWin"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedTo.ctrlKey), "ModifierRemapToCtrl"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedTo.altKey), "ModifierRemapToAlt"),
|
||||
TraceLoggingInt8(static_cast<INT8>(shortcutRemappedTo.shiftKey), "ModifierRemapToShift"),
|
||||
TraceLoggingWideString(GetShortcutHumanReadableString(shortcutRemappedFrom, keyboardMap).c_str(), "HumanRemapFrom"),
|
||||
TraceLoggingWideString(GetShortcutHumanReadableString(shortcutRemappedTo, keyboardMap).c_str(), "HumanRemapTo"),
|
||||
TraceLoggingWideString(appName.c_str(), "TargetApp")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Log an error while trying to send remappings telemetry.
|
||||
void Trace::ErrorSendingKeyAndShortcutRemapLoadedConfiguration() noexcept
|
||||
{
|
||||
TraceLoggingWrite(
|
||||
g_hProvider,
|
||||
"KeyboardManager_ErrorSendingKeyAndShortcutRemapLoadedConfiguration",
|
||||
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||
}
|
||||
|
||||
|
||||
// Log if an error occurs in KBM
|
||||
void Trace::Error(const DWORD errorCode, std::wstring errorMessage, std::wstring methodName) noexcept
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user