|
|
@ -1,8 +1,35 @@
|
|
|
|
using STranslate.Model;
|
|
|
|
using STranslate.Model;
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
using static STranslate.Utils.NativeMethod;
|
|
|
|
|
|
|
|
|
|
|
|
namespace STranslate.Utils
|
|
|
|
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
|
|
|
|
internal class HotKeysUtil
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public static IntPtr mainFormHandle;
|
|
|
|
public static IntPtr mainFormHandle;
|
|
|
@ -16,6 +43,11 @@ 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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 注册快捷键
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="mainFormHandle"></param>
|
|
|
|
public static void RegisterHotKey(IntPtr mainFormHandle)
|
|
|
|
public static void RegisterHotKey(IntPtr mainFormHandle)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HotKeysUtil.mainFormHandle = mainFormHandle;
|
|
|
|
HotKeysUtil.mainFormHandle = mainFormHandle;
|
|
|
@ -41,23 +73,29 @@ namespace STranslate.Utils
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 注销快捷键
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public static void UnRegisterHotKey()
|
|
|
|
public static void UnRegisterHotKey()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
NativeMethod.UnregisterHotKey(mainFormHandle, InputTranslateId);
|
|
|
|
UnregisterHotKey(mainFormHandle, InputTranslateId);
|
|
|
|
NativeMethod.UnregisterHotKey(mainFormHandle, CrosswordTranslateId);
|
|
|
|
UnregisterHotKey(mainFormHandle, CrosswordTranslateId);
|
|
|
|
NativeMethod.UnregisterHotKey(mainFormHandle, ScreenShotTranslateId);
|
|
|
|
UnregisterHotKey(mainFormHandle, ScreenShotTranslateId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 重新注册快捷键
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public static void ReRegisterHotKey()
|
|
|
|
public static void ReRegisterHotKey()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (HotKeys.InputTranslate.Key == 0)
|
|
|
|
if (HotKeys.InputTranslate.Key == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
NativeMethod.UnregisterHotKey(mainFormHandle, InputTranslateId);
|
|
|
|
UnregisterHotKey(mainFormHandle, InputTranslateId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (InputTranslateModifiers != HotKeys.InputTranslate.Modifiers || InputTranslateKey != HotKeys.InputTranslate.Key)
|
|
|
|
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);
|
|
|
|
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)
|
|
|
|
if (HotKeys.CrosswordTranslate.Key == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
NativeMethod.UnregisterHotKey(mainFormHandle, CrosswordTranslateId);
|
|
|
|
UnregisterHotKey(mainFormHandle, CrosswordTranslateId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (CrosswordTranslateModifiers != HotKeys.CrosswordTranslate.Modifiers || CrosswordTranslateKey != HotKeys.CrosswordTranslate.Key)
|
|
|
|
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);
|
|
|
|
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)
|
|
|
|
if (HotKeys.ScreenShotTranslate.Key == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
NativeMethod.UnregisterHotKey(mainFormHandle, ScreenShotTranslateId);
|
|
|
|
UnregisterHotKey(mainFormHandle, ScreenShotTranslateId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ScreenShotTranslateModifiers != HotKeys.ScreenShotTranslate.Modifiers || ScreenShotTranslateKey != HotKeys.ScreenShotTranslate.Key)
|
|
|
|
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);
|
|
|
|
HotKeys.ScreenShotTranslate.Conflict = !NativeMethod.RegisterHotKey(mainFormHandle, ScreenShotTranslateId, HotKeys.ScreenShotTranslate.Modifiers, HotKeys.ScreenShotTranslate.Key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ScreenShotTranslateModifiers = HotKeys.ScreenShotTranslate.Modifiers;
|
|
|
|
ScreenShotTranslateModifiers = HotKeys.ScreenShotTranslate.Modifiers;
|
|
|
|