tmp update struct

dev_without_third_libraries
DESKTOP-3BO4HSG\ksat 2 years ago
parent f01c4d02c9
commit 4a15460c75

@ -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` 即可复制当前鼠标选中内容并翻译
点击软件外部界面任意处或点击 ESCCtrl+Shift+Q 软件则会自动隐藏到后台,即用即走。

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

@ -38,12 +38,8 @@
Visibility="Visible"
Icon="/Images/translate2.ico">
<hc:NotifyIcon.ContextMenu>
<ContextMenu>
<ContextMenu.Style>
<Style>
<Setter Property="ContextMenu.Width" Value="100" />
</Style>
</ContextMenu.Style>
<ContextMenu Style="{StaticResource InputElementBaseStyle}"
Width="120">
<MenuItem x:Name="CrossWordTranslateMenuItem"
Click="CrossWordTranslateMenuItem_Click"
Header="划词翻译" />
@ -55,7 +51,7 @@
Header="输入翻译" />
<Separator/>
<MenuItem Command="hc:ControlCommands.PushMainWindow2Top"
Header="主界面" />
Header="显示主界面" />
<Separator/>
<MenuItem Command="hc:ControlCommands.ShutdownApp"
Header="退出" />

@ -17,7 +17,7 @@ namespace STranslate
{
InitializeComponent();
vm = (MainVM)this.DataContext;
vm = (MainVM)DataContext;
}
/// <summary>

@ -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;
}
}
}

@ -70,6 +70,36 @@ namespace STranslate.Properties {
}
}
/// <summary>
/// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。
/// </summary>
internal static System.Drawing.Icon crossword {
get {
object obj = ResourceManager.GetObject("crossword", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。
/// </summary>
internal static System.Drawing.Icon input {
get {
object obj = ResourceManager.GetObject("input", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。
/// </summary>
internal static System.Drawing.Icon screenshot {
get {
object obj = ResourceManager.GetObject("screenshot", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。
/// </summary>
@ -79,5 +109,15 @@ namespace STranslate.Properties {
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。
/// </summary>
internal static System.Drawing.Icon window {
get {
object obj = ResourceManager.GetObject("window", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
}
}

@ -121,7 +121,19 @@
<data name="copy" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\copy.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="crossword" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\crossword.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="input" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\input.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="screenshot" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\screenshot.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="translate2" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\translate2.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="window" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\window.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

@ -85,7 +85,6 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Model\HotKeys.cs" />
<Compile Include="Utils\ConfigUtil.cs" />
<Compile Include="Utils\GetWordsUtil.cs" />
<Compile Include="Utils\HotKeysUtil.cs" />
@ -140,6 +139,18 @@
<Resource Include="Images\translate2.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Images\crossword.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Images\input.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Images\screenshot.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="Images\window.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Content Include="STranslate.yml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

@ -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;
/// <summary>
/// 注册快捷键
/// </summary>
/// <param name="mainFormHandle"></param>
public static void RegisterHotKey(IntPtr mainFormHandle)
{
HotKeysUtil.mainFormHandle = mainFormHandle;
@ -41,23 +73,29 @@ namespace STranslate.Utils
}
}
/// <summary>
/// 注销快捷键
/// </summary>
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);
}
/// <summary>
/// 重新注册快捷键
/// </summary>
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;

@ -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);
/// <summary>
/// 定义了辅助键的名称(将数字转变为字符以便于记忆,也可去除此枚举而直接使用数值)
/// </summary>
[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

Loading…
Cancel
Save