diff --git a/README.md b/README.md index 9644224..f0f45d3 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,13 @@ WPF 开发的一款即用即走的翻译工具 - [x] 添加百度翻译 API - [x] 实现基本翻译功能 - [x] 优化防止多开 +- [x] 添加划词翻译 - [ ] 优化 DeepL 服务并打包成库引入进项目 - [ ] 添加缓存功能 -- [ ] 添加划词翻译 - [ ] 添加 OCR 翻译 - [ ] 设置 UI 化 - [ ] 使用说明 UI 化 +- [ ] 优化划词翻译(未选中则取消翻译) - [ ] 软件层面识别语种(UI 提示识别语种) - [ ] 翻译制作成插件方式 - [ ] 优化软件发布方式(自动升级) @@ -21,6 +22,8 @@ WPF 开发的一款即用即走的翻译工具 首先在软件运行目录的 `STranslate.yml` 中添加自己的配置,这里推荐百度通用翻译 API 免费版 [申请教程(参照Bob WIKI)](https://bobtranslate.com/service/translate/baidu.html) -打开软件后会静默在后台,等待调用,全局监听快捷键(日后升级成自定义)`Alt` + `A` 即可打开软件主界面,输入需要翻译的内容,选择目标语言,如果识别语种不正确则手动指定即可,翻译结束后选择复制或点击一键复制即可 +打开软件后会静默在后台,等待调用,全局监听快捷键(日后升级成自定义) +- `Ctrl` + `A` 即可打开软件主界面,输入需要翻译的内容,选择目标语言,如果识别语种不正确则手动指定即可,翻译结束后选择复制或点击一键复制即可 +- `Ctrl` + `D` 即可复制当前鼠标选中内容并翻译 点击软件外部界面任意处或点击 ESC,Ctrl+Shift+Q 软件则会自动隐藏到后台,即用即走。 diff --git a/STranslate/Images/crossword.ico b/STranslate/Images/crossword.ico new file mode 100644 index 0000000..e911162 Binary files /dev/null and b/STranslate/Images/crossword.ico differ diff --git a/STranslate/Images/input.ico b/STranslate/Images/input.ico new file mode 100644 index 0000000..1b73842 Binary files /dev/null and b/STranslate/Images/input.ico differ diff --git a/STranslate/Images/screenshot.ico b/STranslate/Images/screenshot.ico new file mode 100644 index 0000000..4cd7d1e Binary files /dev/null and b/STranslate/Images/screenshot.ico differ diff --git a/STranslate/Images/window.ico b/STranslate/Images/window.ico new file mode 100644 index 0000000..b19ddb8 Binary files /dev/null and b/STranslate/Images/window.ico differ diff --git a/STranslate/MainWindow.xaml b/STranslate/MainWindow.xaml index 5b5223e..5b37bb9 100644 --- a/STranslate/MainWindow.xaml +++ b/STranslate/MainWindow.xaml @@ -38,12 +38,8 @@ Visibility="Visible" Icon="/Images/translate2.ico"> - - - - + @@ -55,7 +51,7 @@ Header="输入翻译" /> + Header="显示主界面" /> diff --git a/STranslate/MainWindow.xaml.cs b/STranslate/MainWindow.xaml.cs index 461474d..5ccaab2 100644 --- a/STranslate/MainWindow.xaml.cs +++ b/STranslate/MainWindow.xaml.cs @@ -17,7 +17,7 @@ namespace STranslate { InitializeComponent(); - vm = (MainVM)this.DataContext; + vm = (MainVM)DataContext; } /// diff --git a/STranslate/Model/HotKeys.cs b/STranslate/Model/HotKeys.cs deleted file mode 100644 index 739fd81..0000000 --- a/STranslate/Model/HotKeys.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using static STranslate.Utils.NativeMethod; - -namespace STranslate.Model -{ - public static class HotKeys - { - public static class InputTranslate - { - public static byte Modifiers = (byte)KeyModifiers.Alt; - public static int Key = 65; - public static String Text = "A"; - public static bool Conflict = false; - } - public static class CrosswordTranslate - { - public static byte Modifiers = (byte)KeyModifiers.Ctrl; - public static int Key = 68; - //public static String Text = "F2"; - public static bool Conflict = false; - } - public static class ScreenShotTranslate - { - public static byte Modifiers = (byte)KeyModifiers.Alt; - public static int Key = 83; - public static String Text = "S"; - public static bool Conflict = false; - } - } -} diff --git a/STranslate/Properties/Resources.Designer.cs b/STranslate/Properties/Resources.Designer.cs index 9008840..0224332 100644 --- a/STranslate/Properties/Resources.Designer.cs +++ b/STranslate/Properties/Resources.Designer.cs @@ -70,6 +70,36 @@ namespace STranslate.Properties { } } + /// + /// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。 + /// + internal static System.Drawing.Icon crossword { + get { + object obj = ResourceManager.GetObject("crossword", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + + /// + /// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。 + /// + internal static System.Drawing.Icon input { + get { + object obj = ResourceManager.GetObject("input", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + + /// + /// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。 + /// + internal static System.Drawing.Icon screenshot { + get { + object obj = ResourceManager.GetObject("screenshot", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + /// /// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。 /// @@ -79,5 +109,15 @@ namespace STranslate.Properties { return ((System.Drawing.Icon)(obj)); } } + + /// + /// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。 + /// + internal static System.Drawing.Icon window { + get { + object obj = ResourceManager.GetObject("window", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } } } diff --git a/STranslate/Properties/Resources.resx b/STranslate/Properties/Resources.resx index 56ccc9b..ee880f5 100644 --- a/STranslate/Properties/Resources.resx +++ b/STranslate/Properties/Resources.resx @@ -121,7 +121,19 @@ ..\images\copy.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\images\crossword.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\images\input.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\images\screenshot.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\images\translate2.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\images\window.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/STranslate/STranslate.csproj b/STranslate/STranslate.csproj index a69fdf9..c49f38a 100644 --- a/STranslate/STranslate.csproj +++ b/STranslate/STranslate.csproj @@ -85,7 +85,6 @@ MSBuild:Compile Designer - @@ -140,6 +139,18 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + PreserveNewest diff --git a/STranslate/Utils/HotKeysUtil.cs b/STranslate/Utils/HotKeysUtil.cs index 671990e..2ff2823 100644 --- a/STranslate/Utils/HotKeysUtil.cs +++ b/STranslate/Utils/HotKeysUtil.cs @@ -1,8 +1,35 @@ using STranslate.Model; using System; +using static STranslate.Utils.NativeMethod; namespace STranslate.Utils { + public static class HotKeys + { + public static class InputTranslate + { + public static byte Modifiers = (byte)KeyModifiers.MOD_CTRL; + public static int Key = 65; + public static String Text = "A"; + public static bool Conflict = false; + } + public static class CrosswordTranslate + { + public static byte Modifiers = (byte)KeyModifiers.MOD_CTRL; + public static int Key = 68; + public static String Text = "D"; + public static bool Conflict = false; + } + public static class ScreenShotTranslate + { + public static byte Modifiers = (byte)KeyModifiers.MOD_CTRL; + public static int Key = 83; + public static String Text = "S"; + public static bool Conflict = false; + } + } + + internal class HotKeysUtil { public static IntPtr mainFormHandle; @@ -16,6 +43,11 @@ namespace STranslate.Utils public static int ScreenShotTranslateId = 856; public static byte ScreenShotTranslateModifiers; public static int ScreenShotTranslateKey; + + /// + /// 注册快捷键 + /// + /// public static void RegisterHotKey(IntPtr mainFormHandle) { HotKeysUtil.mainFormHandle = mainFormHandle; @@ -41,23 +73,29 @@ namespace STranslate.Utils } } + /// + /// 注销快捷键 + /// public static void UnRegisterHotKey() { - NativeMethod.UnregisterHotKey(mainFormHandle, InputTranslateId); - NativeMethod.UnregisterHotKey(mainFormHandle, CrosswordTranslateId); - NativeMethod.UnregisterHotKey(mainFormHandle, ScreenShotTranslateId); + UnregisterHotKey(mainFormHandle, InputTranslateId); + UnregisterHotKey(mainFormHandle, CrosswordTranslateId); + UnregisterHotKey(mainFormHandle, ScreenShotTranslateId); } + /// + /// 重新注册快捷键 + /// public static void ReRegisterHotKey() { if (HotKeys.InputTranslate.Key == 0) { - NativeMethod.UnregisterHotKey(mainFormHandle, InputTranslateId); + UnregisterHotKey(mainFormHandle, InputTranslateId); } else if (InputTranslateModifiers != HotKeys.InputTranslate.Modifiers || InputTranslateKey != HotKeys.InputTranslate.Key) { { - NativeMethod.UnregisterHotKey(mainFormHandle, InputTranslateId); + UnregisterHotKey(mainFormHandle, InputTranslateId); HotKeys.InputTranslate.Conflict = !NativeMethod.RegisterHotKey(mainFormHandle, InputTranslateId, HotKeys.InputTranslate.Modifiers, HotKeys.InputTranslate.Key); } } @@ -66,12 +104,12 @@ namespace STranslate.Utils if (HotKeys.CrosswordTranslate.Key == 0) { - NativeMethod.UnregisterHotKey(mainFormHandle, CrosswordTranslateId); + UnregisterHotKey(mainFormHandle, CrosswordTranslateId); } else if (CrosswordTranslateModifiers != HotKeys.CrosswordTranslate.Modifiers || CrosswordTranslateKey != HotKeys.CrosswordTranslate.Key) { { - NativeMethod.UnregisterHotKey(mainFormHandle, CrosswordTranslateId); + UnregisterHotKey(mainFormHandle, CrosswordTranslateId); HotKeys.CrosswordTranslate.Conflict = !NativeMethod.RegisterHotKey(mainFormHandle, CrosswordTranslateId, HotKeys.CrosswordTranslate.Modifiers, HotKeys.CrosswordTranslate.Key); } } @@ -80,11 +118,11 @@ namespace STranslate.Utils if (HotKeys.ScreenShotTranslate.Key == 0) { - NativeMethod.UnregisterHotKey(mainFormHandle, ScreenShotTranslateId); + UnregisterHotKey(mainFormHandle, ScreenShotTranslateId); } else if (ScreenShotTranslateModifiers != HotKeys.ScreenShotTranslate.Modifiers || ScreenShotTranslateKey != HotKeys.ScreenShotTranslate.Key) { - NativeMethod.UnregisterHotKey(mainFormHandle, ScreenShotTranslateId); + UnregisterHotKey(mainFormHandle, ScreenShotTranslateId); HotKeys.ScreenShotTranslate.Conflict = !NativeMethod.RegisterHotKey(mainFormHandle, ScreenShotTranslateId, HotKeys.ScreenShotTranslate.Modifiers, HotKeys.ScreenShotTranslate.Key); } ScreenShotTranslateModifiers = HotKeys.ScreenShotTranslate.Modifiers; diff --git a/STranslate/Utils/NativeMethod.cs b/STranslate/Utils/NativeMethod.cs index 917ad4d..15caf9e 100644 --- a/STranslate/Utils/NativeMethod.cs +++ b/STranslate/Utils/NativeMethod.cs @@ -206,17 +206,13 @@ namespace STranslate.Utils [DllImport("user32.dll")] public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hPos, int x, int y, int cx, int cy, uint nflags); - /// - /// 定义了辅助键的名称(将数字转变为字符以便于记忆,也可去除此枚举而直接使用数值) - /// - [Flags()] - public enum KeyModifiers + internal enum KeyModifiers { - None = 0, - Alt = 1, - Ctrl = 2, - Shift = 4, - WindowsKey = 8 + MOD_NONE = 0x0, + MOD_ALT = 0x1, + MOD_CTRL = 0x2, + MOD_SHIFT = 0x4, + MOD_WIN = 0x8 } #region Clipboard