diff --git a/STranslate/MainWindow.xaml.cs b/STranslate/MainWindow.xaml.cs index 11a2834..6d01640 100644 --- a/STranslate/MainWindow.xaml.cs +++ b/STranslate/MainWindow.xaml.cs @@ -149,6 +149,10 @@ namespace STranslate { this.ScreenshotTranslateMenuItem_Click(null, null); } + else if (wParam.ToString().Equals(HotKeysUtil.OpenMainWindowId + "")) + { + this.OpenMainWin_Click(null, null); + } break; } return IntPtr.Zero; diff --git a/STranslate/STranslate.yml b/STranslate/STranslate.yml index b36eebd..142d807 100644 --- a/STranslate/STranslate.yml +++ b/STranslate/STranslate.yml @@ -3,4 +3,4 @@ baidu: appid: secretKey: deepl: - url: http://127.0.0.1:8000/translate \ No newline at end of file + url: http://127.0.0.1:8000/translate diff --git a/STranslate/Utils/HotKeysUtil.cs b/STranslate/Utils/HotKeysUtil.cs index f7ec501..b563fe6 100644 --- a/STranslate/Utils/HotKeysUtil.cs +++ b/STranslate/Utils/HotKeysUtil.cs @@ -28,6 +28,14 @@ namespace STranslate.Utils public static String Text = "S"; public static bool Conflict = false; } + + public static class OpenMainWindow + { + public static byte Modifiers = (byte)KeyModifiers.MOD_ALT; + public static int Key = 71; + public static String Text = "G"; + public static bool Conflict = false; + } } internal class HotKeysUtil @@ -43,6 +51,9 @@ namespace STranslate.Utils public static int ScreenShotTranslateId = 856; public static byte ScreenShotTranslateModifiers; public static int ScreenShotTranslateKey; + public static int OpenMainWindowId = 857; + public static byte OpenMainWindowModifiers; + public static int OpenMainWindowKey; /// /// 注册快捷键 @@ -71,6 +82,10 @@ namespace STranslate.Utils { HotKeys.ScreenShotTranslate.Conflict = !NativeMethod.RegisterHotKey(mainFormHandle, ScreenShotTranslateId, HotKeys.ScreenShotTranslate.Modifiers, HotKeys.ScreenShotTranslate.Key); } + if (HotKeys.OpenMainWindow.Key != 0) + { + HotKeys.OpenMainWindow.Conflict = !NativeMethod.RegisterHotKey(mainFormHandle, OpenMainWindowId, HotKeys.OpenMainWindow.Modifiers, HotKeys.OpenMainWindow.Key); + } } /// @@ -81,6 +96,7 @@ namespace STranslate.Utils UnregisterHotKey(mainFormHandle, InputTranslateId); UnregisterHotKey(mainFormHandle, CrosswordTranslateId); UnregisterHotKey(mainFormHandle, ScreenShotTranslateId); + UnregisterHotKey(mainFormHandle, OpenMainWindowId); } /// @@ -127,6 +143,18 @@ namespace STranslate.Utils } ScreenShotTranslateModifiers = HotKeys.ScreenShotTranslate.Modifiers; ScreenShotTranslateKey = HotKeys.ScreenShotTranslate.Key; + + if (HotKeys.OpenMainWindow.Key == 0) + { + UnregisterHotKey(mainFormHandle, OpenMainWindowId); + } + else if (OpenMainWindowModifiers != HotKeys.OpenMainWindow.Modifiers || OpenMainWindowKey != HotKeys.OpenMainWindow.Key) + { + UnregisterHotKey(mainFormHandle, OpenMainWindowId); + HotKeys.OpenMainWindow.Conflict = !NativeMethod.RegisterHotKey(mainFormHandle, OpenMainWindowId, HotKeys.OpenMainWindow.Modifiers, HotKeys.OpenMainWindow.Key); + } + OpenMainWindowModifiers = HotKeys.OpenMainWindow.Modifiers; + OpenMainWindowKey = HotKeys.OpenMainWindow.Key; } } } \ No newline at end of file diff --git a/STranslate/ViewModel/MainVM.cs b/STranslate/ViewModel/MainVM.cs index 0f118c9..5f708ce 100644 --- a/STranslate/ViewModel/MainVM.cs +++ b/STranslate/ViewModel/MainVM.cs @@ -18,7 +18,7 @@ namespace STranslate.ViewModel //[System.Runtime.InteropServices.DllImport("deepl.dll", EntryPoint = "run")] //extern static void run(); - public string defaultApi = "http://127.0.0.1:8000/translate"; + public string defaultApi = "http://127.0.0.1:8000/translate"; //https://deepl.deno.dev/translate private string ConfigPath => $"{AppDomain.CurrentDomain.BaseDirectory}STranslate.yml"; public ConfigModel config = new ConfigModel(); private static Dictionary LanguageEnumDict { get => TranslateUtil.GetEnumList(); }