Skip to content

Code Quality: Migrated GetKeyState to CsWin32 #15173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/Files.App/Helpers/Interop/NativeWinApiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ namespace Files.App.Helpers
{
public sealed class NativeWinApiHelper
{
[DllImport("user32.dll")]
public static extern short GetKeyState(short code);

[DllImport("Shcore.dll", SetLastError = true)]
public static extern int GetDpiForMonitor(IntPtr hmonitor, uint dpiType, out uint dpiX, out uint dpiY);

Expand Down
7 changes: 1 addition & 6 deletions src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,7 @@ public static extern IntPtr SetWindowLongPtr64(
WindowLongFlags nIndex,
IntPtr dwNewLong
);

[DllImport("User32.dll")]
public extern static short GetKeyState(
int n
);


[DllImport("shell32.dll")]
public static extern IntPtr SHBrowseForFolder(
ref BROWSEINFO lpbi
Expand Down
3 changes: 2 additions & 1 deletion src/Files.App/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ SetActiveWindow
CopyFileFromApp
MoveFileFromApp
DeleteFileFromApp
RemoveDirectoryFromApp
RemoveDirectoryFromApp
GetKeyState
3 changes: 2 additions & 1 deletion src/Files.App/Views/Layouts/BaseGroupableLayoutPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.UI.Xaml.Input;
using Windows.System;
using Windows.UI.Core;
using Windows.Win32;

namespace Files.App.Views.Layouts
{
Expand Down Expand Up @@ -287,7 +288,7 @@ protected virtual async void RenameTextBox_LostFocus(object sender, RoutedEventA
protected async void RenameTextBox_KeyDown(object sender, KeyRoutedEventArgs e)
{
var textBox = (TextBox)sender;
var isShiftPressed = (Win32PInvoke.GetKeyState((int)VirtualKey.Shift) & KEY_DOWN_MASK) != 0;
var isShiftPressed = (PInvoke.GetKeyState((int)VirtualKey.Shift) & KEY_DOWN_MASK) != 0;

switch (e.Key)
{
Expand Down
Loading