Skip to content

Commit a2e004a

Browse files
committed
enable the use of Win hotkey
1 parent 1a54eed commit a2e004a

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

Flow.Launcher.Infrastructure/Hotkey/HotkeyModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,11 @@ public bool Validate(bool validateKeyGestrue = false)
167167
case Key.RightCtrl:
168168
case Key.LeftShift:
169169
case Key.RightShift:
170-
case Key.LWin:
171-
case Key.RWin:
172170
case Key.None:
173171
return false;
172+
case Key.LWin:
173+
case Key.RWin:
174+
return true;
174175
default:
175176
if (validateKeyGestrue)
176177
{

Flow.Launcher/Flow.Launcher.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
</ItemGroup>
8484

8585
<ItemGroup>
86+
<PackageReference Include="ChefKeys" Version="0.1.2" />
8687
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
8788
<PackageReference Include="Fody" Version="6.5.4">
8889
<PrivateAssets>all</PrivateAssets>

Flow.Launcher/Helper/HotKeyMapper.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using Flow.Launcher.Core.Resource;
77
using Flow.Launcher.ViewModel;
88
using Flow.Launcher.Core;
9+
using ChefKeys;
10+
using System.Globalization;
911

1012
namespace Flow.Launcher.Helper;
1113

@@ -29,15 +31,40 @@ internal static void OnToggleHotkey(object sender, HotkeyEventArgs args)
2931
_mainViewModel.ToggleFlowLauncher();
3032
}
3133

34+
internal static void OnToggleHotkeyWithChefKeys()
35+
{
36+
if (!_mainViewModel.ShouldIgnoreHotkeys())
37+
_mainViewModel.ToggleFlowLauncher();
38+
}
39+
3240
private static void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)
3341
{
42+
if (hotkeyStr == "LWin" || hotkeyStr == "RWin")
43+
{
44+
SetWithChefKeys(hotkeyStr);
45+
return;
46+
}
47+
3448
var hotkey = new HotkeyModel(hotkeyStr);
3549
SetHotkey(hotkey, action);
3650
}
3751

52+
private static void SetWithChefKeys(string hotkeyStr)
53+
{
54+
ChefKeysManager.RegisterHotkey(hotkeyStr, hotkeyStr, OnToggleHotkeyWithChefKeys);
55+
ChefKeysManager.Start();
56+
}
57+
3858
internal static void SetHotkey(HotkeyModel hotkey, EventHandler<HotkeyEventArgs> action)
3959
{
4060
string hotkeyStr = hotkey.ToString();
61+
62+
if (hotkeyStr == "LWin" || hotkeyStr == "RWin")
63+
{
64+
SetWithChefKeys(hotkeyStr);
65+
return;
66+
}
67+
4168
try
4269
{
4370
HotkeyManager.Current.AddOrReplace(hotkeyStr, hotkey.CharKey, hotkey.ModifierKeys, action);
@@ -52,12 +79,24 @@ internal static void SetHotkey(HotkeyModel hotkey, EventHandler<HotkeyEventArgs>
5279

5380
internal static void RemoveHotkey(string hotkeyStr)
5481
{
82+
if (hotkeyStr == "LWin" || hotkeyStr == "RWin")
83+
{
84+
RemoveWithChefKeys(hotkeyStr);
85+
return;
86+
}
87+
5588
if (!string.IsNullOrEmpty(hotkeyStr))
5689
{
5790
HotkeyManager.Current.Remove(hotkeyStr);
5891
}
5992
}
6093

94+
private static void RemoveWithChefKeys(string hotkeyStr)
95+
{
96+
ChefKeysManager.UnregisterHotkey(hotkeyStr);
97+
ChefKeysManager.Stop();
98+
}
99+
61100
internal static void LoadCustomPluginHotkey()
62101
{
63102
if (_settings.CustomPluginHotkeys == null)

Flow.Launcher/HotkeyControlDialog.xaml.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Windows;
55
using System.Windows.Input;
6+
using ChefKeys;
67
using Flow.Launcher.Core.Resource;
78
using Flow.Launcher.Helper;
89
using Flow.Launcher.Infrastructure.Hotkey;
@@ -46,6 +47,9 @@ public HotkeyControlDialog(string hotkey, string defaultHotkey, IHotkeySettings
4647
SetKeysToDisplay(CurrentHotkey);
4748

4849
InitializeComponent();
50+
51+
ChefKeysManager.StartMenuEnableBlocking = true;
52+
ChefKeysManager.Start();
4953
}
5054

5155
private void Reset(object sender, RoutedEventArgs routedEventArgs)
@@ -61,12 +65,18 @@ private void Delete(object sender, RoutedEventArgs routedEventArgs)
6165

6266
private void Cancel(object sender, RoutedEventArgs routedEventArgs)
6367
{
68+
ChefKeysManager.StartMenuEnableBlocking = false;
69+
ChefKeysManager.Stop();
70+
6471
ResultType = EResultType.Cancel;
6572
Hide();
6673
}
6774

6875
private void Save(object sender, RoutedEventArgs routedEventArgs)
6976
{
77+
ChefKeysManager.StartMenuEnableBlocking = false;
78+
ChefKeysManager.Stop();
79+
7080
if (KeysToDisplay.Count == 1 && KeysToDisplay[0] == EmptyHotkey)
7181
{
7282
ResultType = EResultType.Delete;
@@ -85,6 +95,9 @@ private void OnPreviewKeyDown(object sender, KeyEventArgs e)
8595
//when alt is pressed, the real key should be e.SystemKey
8696
Key key = e.Key == Key.System ? e.SystemKey : e.Key;
8797

98+
if (ChefKeysManager.StartMenuBlocked && key.ToString() == ChefKeysManager.StartMenuSimulatedKey)
99+
return;
100+
88101
SpecialKeyState specialKeyState = GlobalHotkey.CheckModifiers();
89102

90103
var hotkeyModel = new HotkeyModel(

0 commit comments

Comments
 (0)