mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
* basic logic working * Added a literal for ignore flag which cna be shared by all the files * Added a condition that the other modifier keys should not be pressed * Added comments to describe each scenario * sometimes when multiple modified keys were involved the shift+tab key press was also being invoked, so added an additional check in the IsValid function * use variable for vk_tab * remove new line before initializing dwextraInfo * move flag check if the filterKeyboardevent function * use windows.system.virtualkey.shift instead of defining a constant for the shift key code * removed latest settings to use internal settings instead. Removed the validity check while still within the hotkey other than if it's tab or shift+tab * add a function to send input to the system instead of duplicating the send input code * remove VKSHIFT declaration * display all shortcuts/keys except tab and shift+tab * remove header that is no longer needed
131 lines
3.5 KiB
C#
131 lines
3.5 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System.Text;
|
|
using System.Text.Json.Serialization;
|
|
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Lib
|
|
{
|
|
public class HotkeySettings
|
|
{
|
|
private const int VKTAB = 0x09;
|
|
|
|
public HotkeySettings()
|
|
{
|
|
Win = false;
|
|
Ctrl = false;
|
|
Alt = false;
|
|
Shift = false;
|
|
Code = 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="HotkeySettings"/> class.
|
|
/// </summary>
|
|
/// <param name="win">Should Windows key be used</param>
|
|
/// <param name="ctrl">Should Ctrl key be used</param>
|
|
/// <param name="alt">Should Alt key be used</param>
|
|
/// <param name="shift">Should Shift key be used</param>
|
|
/// <param name="code">Go to https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes to see list of v-keys</param>
|
|
public HotkeySettings(bool win, bool ctrl, bool alt, bool shift, int code)
|
|
{
|
|
Win = win;
|
|
Ctrl = ctrl;
|
|
Alt = alt;
|
|
Shift = shift;
|
|
Code = code;
|
|
}
|
|
|
|
public HotkeySettings Clone()
|
|
{
|
|
return new HotkeySettings(Win, Ctrl, Alt, Shift, Code);
|
|
}
|
|
|
|
[JsonPropertyName("win")]
|
|
public bool Win { get; set; }
|
|
|
|
[JsonPropertyName("ctrl")]
|
|
public bool Ctrl { get; set; }
|
|
|
|
[JsonPropertyName("alt")]
|
|
public bool Alt { get; set; }
|
|
|
|
[JsonPropertyName("shift")]
|
|
public bool Shift { get; set; }
|
|
|
|
[JsonPropertyName("code")]
|
|
public int Code { get; set; }
|
|
|
|
// This is currently needed for FancyZones, we need to unify these two objects
|
|
// see src\common\settings_objects.h
|
|
[JsonPropertyName("key")]
|
|
public string Key { get; set; } = string.Empty;
|
|
|
|
public override string ToString()
|
|
{
|
|
StringBuilder output = new StringBuilder();
|
|
|
|
if (Win)
|
|
{
|
|
output.Append("Win + ");
|
|
}
|
|
|
|
if (Ctrl)
|
|
{
|
|
output.Append("Ctrl + ");
|
|
}
|
|
|
|
if (Alt)
|
|
{
|
|
output.Append("Alt + ");
|
|
}
|
|
|
|
if (Shift)
|
|
{
|
|
output.Append("Shift + ");
|
|
}
|
|
|
|
if (Code > 0)
|
|
{
|
|
var localKey = Helper.GetKeyName((uint)Code);
|
|
output.Append(localKey);
|
|
}
|
|
else if (output.Length >= 2)
|
|
{
|
|
output.Remove(output.Length - 2, 2);
|
|
}
|
|
|
|
return output.ToString();
|
|
}
|
|
|
|
public bool IsValid()
|
|
{
|
|
if (IsAccessibleShortcut())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return (Alt || Ctrl || Win || Shift) && Code != 0;
|
|
}
|
|
|
|
public bool IsEmpty()
|
|
{
|
|
return !Alt && !Ctrl && !Win && !Shift && Code == 0;
|
|
}
|
|
|
|
public bool IsAccessibleShortcut()
|
|
{
|
|
// Shift+Tab and Tab are accessible shortcuts
|
|
if ((!Alt && !Ctrl && !Win && Shift && Code == VKTAB)
|
|
|| (!Alt && !Ctrl && !Win && !Shift && Code == VKTAB))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|