-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29efd34
commit d7abf8f
Showing
79 changed files
with
23,093 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.8.34205.153 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WhichKey", "WhichKey\WhichKey.csproj", "{A6655C53-BA5D-48C6-8A84-C033FFD45C2B}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{A6655C53-BA5D-48C6-8A84-C033FFD45C2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A6655C53-BA5D-48C6-8A84-C033FFD45C2B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A6655C53-BA5D-48C6-8A84-C033FFD45C2B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A6655C53-BA5D-48C6-8A84-C033FFD45C2B}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {814AD2CE-BFB7-4F71-BF1F-C3D289AF9357} | ||
EndGlobalSection | ||
EndGlobal |
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,7 @@ | ||
<Application x:Class="WhichKey.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
DispatcherUnhandledException="App_OnDispatcherUnhandledException" | ||
> | ||
<Application.Resources/> | ||
</Application> |
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,87 @@ | ||
using NHotkey; | ||
using NHotkey.Wpf; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Runtime.InteropServices; | ||
using System.Windows; | ||
using System.Windows.Input; | ||
using System.Windows.Threading; | ||
using WhichKey.ViewModels; | ||
|
||
|
||
namespace WhichKey | ||
{ | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App | ||
{ | ||
public Window _mainWindow = new MainWindow(); | ||
|
||
protected override void OnStartup(StartupEventArgs e) | ||
{ | ||
_mainWindow.PreviewKeyDown += _mainWindow_PreviewKeyDown; | ||
_mainWindow.StateChanged+= MainWindow_OnStateChanged; | ||
HotkeyManager.Current.AddOrReplace("ShowWindow", Key.None, ModifierKeys.Control | ModifierKeys.Alt, ShowWindow); | ||
base.OnStartup(e); | ||
} | ||
|
||
private void MainWindow_OnStateChanged(object? sender, EventArgs e) | ||
{ | ||
|
||
if (_mainWindow.WindowState == WindowState.Minimized) | ||
{ | ||
_mainWindow.Hide(); | ||
} | ||
} | ||
|
||
private void _mainWindow_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e) | ||
{ | ||
if (e.Key == Key.Escape) | ||
{ | ||
_mainWindow.WindowState = WindowState.Minimized; | ||
} | ||
} | ||
|
||
private void ShowWindow(object? sender, HotkeyEventArgs e) | ||
{ | ||
var appName = GetActiveProcessFileName(); | ||
_mainWindow.DataContext = new MainViewModel(appName.ToLower()); | ||
_mainWindow.Show(); | ||
_mainWindow.Activate(); | ||
_mainWindow.WindowState=WindowState.Normal; | ||
|
||
e.Handled = true; | ||
if (_mainWindow is MainWindow mainWindow) | ||
{ | ||
if (mainWindow.ShortcutListingView.SearchTextBox != null) | ||
{ | ||
mainWindow.ShortcutListingView.SearchTextBox.Focus(); | ||
mainWindow.ShortcutListingView.SearchTextBox.SelectAll(); | ||
} | ||
} | ||
} | ||
|
||
private void App_OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) | ||
{ | ||
var text = $"\n\n{DateTime.Now}\n{e.Exception.ToStringDemystified()}"; | ||
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log.txt"); | ||
File.AppendAllText(path, text); | ||
} | ||
|
||
[DllImport("user32.dll")] | ||
public static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out uint processId); | ||
|
||
[DllImport("user32.dll")] | ||
private static extern IntPtr GetForegroundWindow(); | ||
|
||
static string GetActiveProcessFileName() | ||
{ | ||
var hwnd = GetForegroundWindow(); | ||
GetWindowThreadProcessId(hwnd, out var pid); | ||
var p = Process.GetProcessById((int)pid); | ||
return p.ProcessName; | ||
} | ||
} | ||
|
||
} |
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,10 @@ | ||
using System.Windows; | ||
|
||
[assembly: ThemeInfo( | ||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | ||
//(used if a resource is not found in the page, | ||
// or application resource dictionaries) | ||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | ||
//(used if a resource is not found in the page, | ||
// app, or any theme specific resource dictionaries) | ||
)] |
Oops, something went wrong.