Skip to content

Commit

Permalink
Focus search box with Win+Alt+S (#10)
Browse files Browse the repository at this point in the history
Closes #10, #12
  • Loading branch information
srwi committed Nov 7, 2020
1 parent f3ad9e5 commit 26be5f6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions EverythingToolbar/EverythingToolbar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="NHotkey.Wpf">
<Version>2.1.0</Version>
</PackageReference>
<PackageReference Include="NLog">
<Version>4.7.5</Version>
</PackageReference>
Expand Down
19 changes: 19 additions & 0 deletions EverythingToolbar/ToolbarControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using CSDeskBand;
using NHotkey;
using NHotkey.Wpf;
using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
Expand Down Expand Up @@ -37,6 +40,8 @@ public ToolbarControl()
searchResultsPopup.searchResultsView.EndOfListReached += OnEndOfListReached;
searchResultsPopup.searchResultsView.FilterChanged += OnFilterChanged;
searchResultsPopup.Closed += SearchResultsPopup_Closed;

HotkeyManager.Current.AddOrReplace("FocusSearchBox", Key.S, ModifierKeys.Windows | ModifierKeys.Alt, FocusSearchBox);
}

public static void SetTaskbarEdge(Edge edge)
Expand Down Expand Up @@ -304,5 +309,19 @@ bool ApplyItemTemplate(string templateName)
return false;
}
}

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetForegroundWindow(IntPtr hWnd);

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr FindWindow(String lpClassName, String lpWindowName);

private void FocusSearchBox(object sender, HotkeyEventArgs e)
{
IntPtr taskbar = FindWindow("Shell_traywnd", "");
SetForegroundWindow(taskbar);
Keyboard.Focus(searchBox);
}
}
}

0 comments on commit 26be5f6

Please sign in to comment.