-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Tab Trap in SettingsHotkey Custom Control (#7136)
* 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
- Loading branch information
1 parent
8a81bea
commit cfe2bbd
Showing
8 changed files
with
247 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ public | |
{ | ||
WPARAM message; | ||
int key; | ||
DWORD dwExtraInfo; | ||
}; | ||
|
||
public | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/core/Microsoft.PowerToys.Settings.UI/Helpers/NativeKeyboardHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// 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; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Microsoft.PowerToys.Settings.UI.Helpers | ||
{ | ||
internal static class NativeKeyboardHelper | ||
{ | ||
[StructLayout(LayoutKind.Sequential)] | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Matching Native Structure")] | ||
internal struct INPUT | ||
{ | ||
internal INPUTTYPE type; | ||
internal InputUnion data; | ||
|
||
internal static int Size | ||
{ | ||
get { return Marshal.SizeOf(typeof(INPUT)); } | ||
} | ||
} | ||
|
||
[StructLayout(LayoutKind.Explicit)] | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Matching Native Structure")] | ||
internal struct InputUnion | ||
{ | ||
[FieldOffset(0)] | ||
internal MOUSEINPUT mi; | ||
[FieldOffset(0)] | ||
internal KEYBDINPUT ki; | ||
[FieldOffset(0)] | ||
internal HARDWAREINPUT hi; | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Matching Native Structure")] | ||
internal struct MOUSEINPUT | ||
{ | ||
internal int dx; | ||
internal int dy; | ||
internal int mouseData; | ||
internal uint dwFlags; | ||
internal uint time; | ||
internal UIntPtr dwExtraInfo; | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Matching Native Structure")] | ||
internal struct KEYBDINPUT | ||
{ | ||
internal short wVk; | ||
internal short wScan; | ||
internal uint dwFlags; | ||
internal int time; | ||
internal UIntPtr dwExtraInfo; | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Matching Native Structure")] | ||
internal struct HARDWAREINPUT | ||
{ | ||
internal int uMsg; | ||
internal short wParamL; | ||
internal short wParamH; | ||
} | ||
|
||
internal enum INPUTTYPE : uint | ||
{ | ||
INPUT_MOUSE = 0, | ||
INPUT_KEYBOARD = 1, | ||
INPUT_HARDWARE = 2, | ||
} | ||
|
||
[Flags] | ||
internal enum KeyEventF | ||
{ | ||
KeyDown = 0x0000, | ||
ExtendedKey = 0x0001, | ||
KeyUp = 0x0002, | ||
Unicode = 0x0004, | ||
Scancode = 0x0008, | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/core/Microsoft.PowerToys.Settings.UI/Helpers/NativeMethods.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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.Runtime.InteropServices; | ||
|
||
namespace Microsoft.PowerToys.Settings.UI.Helpers | ||
{ | ||
internal static class NativeMethods | ||
{ | ||
[DllImport("user32.dll")] | ||
internal static extern uint SendInput(uint nInputs, NativeKeyboardHelper.INPUT[] pInputs, int cbSize); | ||
|
||
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)] | ||
internal static extern short GetAsyncKeyState(int vKey); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters