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);
}
else if (wParam.ToString().Equals(HotKeysUtil.OpenMainWindowId + ""))
{
this.OpenMainWin_Click(null, null);
}
break;
}
return IntPtr.Zero;

@ -3,4 +3,4 @@ baidu:
appid:
secretKey:
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 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;
/// <summary>
/// 注册快捷键
@ -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);
}
}
/// <summary>
@ -81,6 +96,7 @@ namespace STranslate.Utils
UnregisterHotKey(mainFormHandle, InputTranslateId);
UnregisterHotKey(mainFormHandle, CrosswordTranslateId);
UnregisterHotKey(mainFormHandle, ScreenShotTranslateId);
UnregisterHotKey(mainFormHandle, OpenMainWindowId);
}
/// <summary>
@ -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;
}
}
}

@ -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<string, LanguageEnum> LanguageEnumDict { get => TranslateUtil.GetEnumList<LanguageEnum>(); }

Loading…
Cancel
Save