feat: add global key for open window

dev_without_third_libraries
DESKTOP-3BO4HSG\ksat 2 years ago
parent c0b666f4f9
commit c70addc13e

@ -149,6 +149,10 @@ namespace STranslate
{ {
this.ScreenshotTranslateMenuItem_Click(null, null); this.ScreenshotTranslateMenuItem_Click(null, null);
} }
else if (wParam.ToString().Equals(HotKeysUtil.OpenMainWindowId + ""))
{
this.OpenMainWin_Click(null, null);
}
break; break;
} }
return IntPtr.Zero; return IntPtr.Zero;

@ -3,4 +3,4 @@ baidu:
appid: appid:
secretKey: secretKey:
deepl: deepl:
url: http://127.0.0.1:8000/translate url: http://127.0.0.1:8000/translate

@ -28,6 +28,14 @@ namespace STranslate.Utils
public static String Text = "S"; public static String Text = "S";
public static bool Conflict = false; 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 internal class HotKeysUtil
@ -43,6 +51,9 @@ namespace STranslate.Utils
public static int ScreenShotTranslateId = 856; public static int ScreenShotTranslateId = 856;
public static byte ScreenShotTranslateModifiers; public static byte ScreenShotTranslateModifiers;
public static int ScreenShotTranslateKey; public static int ScreenShotTranslateKey;
public static int OpenMainWindowId = 857;
public static byte OpenMainWindowModifiers;
public static int OpenMainWindowKey;
/// <summary> /// <summary>
/// 注册快捷键 /// 注册快捷键
@ -71,6 +82,10 @@ namespace STranslate.Utils
{ {
HotKeys.ScreenShotTranslate.Conflict = !NativeMethod.RegisterHotKey(mainFormHandle, ScreenShotTranslateId, HotKeys.ScreenShotTranslate.Modifiers, HotKeys.ScreenShotTranslate.Key); 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);
}
} }
/// <summary> /// <summary>
@ -81,6 +96,7 @@ namespace STranslate.Utils
UnregisterHotKey(mainFormHandle, InputTranslateId); UnregisterHotKey(mainFormHandle, InputTranslateId);
UnregisterHotKey(mainFormHandle, CrosswordTranslateId); UnregisterHotKey(mainFormHandle, CrosswordTranslateId);
UnregisterHotKey(mainFormHandle, ScreenShotTranslateId); UnregisterHotKey(mainFormHandle, ScreenShotTranslateId);
UnregisterHotKey(mainFormHandle, OpenMainWindowId);
} }
/// <summary> /// <summary>
@ -127,6 +143,18 @@ namespace STranslate.Utils
} }
ScreenShotTranslateModifiers = HotKeys.ScreenShotTranslate.Modifiers; ScreenShotTranslateModifiers = HotKeys.ScreenShotTranslate.Modifiers;
ScreenShotTranslateKey = HotKeys.ScreenShotTranslate.Key; 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;
} }
} }
} }

@ -18,7 +18,7 @@ namespace STranslate.ViewModel
//[System.Runtime.InteropServices.DllImport("deepl.dll", EntryPoint = "run")] //[System.Runtime.InteropServices.DllImport("deepl.dll", EntryPoint = "run")]
//extern static void 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"; private string ConfigPath => $"{AppDomain.CurrentDomain.BaseDirectory}STranslate.yml";
public ConfigModel config = new ConfigModel(); public ConfigModel config = new ConfigModel();
private static Dictionary<string, LanguageEnum> LanguageEnumDict { get => TranslateUtil.GetEnumList<LanguageEnum>(); } private static Dictionary<string, LanguageEnum> LanguageEnumDict { get => TranslateUtil.GetEnumList<LanguageEnum>(); }

Loading…
Cancel
Save