feat: perf shortcuts and perf view

dev_without_third_libraries
DESKTOP-3BO4HSG\ksat 2 years ago
parent 3632d2da83
commit 63438cf85f

@ -25,12 +25,12 @@ WPF 开发的一款即用即走的翻译工具
打开软件后会静默在后台,等待调用,全局监听快捷键(日后升级成自定义) 打开软件后会静默在后台,等待调用,全局监听快捷键(日后升级成自定义)
- `Alt` + `A` 即可打开软件主界面,输入需要翻译的内容,选择目标语言,如果识别语种不正确则手动指定即可,翻译结束后选择复制或点击一键复制即可 - `Alt` + `A` 即可打开软件主界面,输入需要翻译的内容,选择目标语言,如果识别语种不正确则手动指定即可,翻译结束后选择复制或点击一键复制即可
- `Ctrl` + `D` 即可复制当前鼠标选中内容并翻译 - `Alt` + `D` 即可复制当前鼠标选中内容并翻译
点击软件外部界面任意处或点击 ESCCtrl+Shift+Q 软件则会自动隐藏到后台,即用即走。 点击软件外部界面任意处或点击 ESCCtrl+Shift+Q 软件则会自动隐藏到后台,即用即走。
## 参考项目 ## 参考项目
部分功能参考如下项目,在此表示感谢 监听全局快捷键功能参考如下项目,在此表示感谢
- [https://github.com/NPCDW/WpfTool](https://github.com/NPCDW/WpfTool) - [https://github.com/NPCDW/WpfTool](https://github.com/NPCDW/WpfTool)

@ -67,19 +67,18 @@
BorderBrush="#000" BorderBrush="#000"
BorderThickness="1" BorderThickness="1"
CornerRadius="4" CornerRadius="4"
Margin="5" Margin="5">
Height="{Binding ElementName=Input, Path=Height}">
<TextBox x:Name="TextBoxInput" <TextBox x:Name="TextBoxInput"
Background="Transparent" Background="Transparent"
BorderBrush="{x:Null}" BorderBrush="{x:Null}"
Margin="5" Margin="5"
BorderThickness="0" BorderThickness="0"
FontSize="18" FontSize="18"
Width="{Binding ElementName=BorderInput, Path=ActualWidth}"
TextWrapping="Wrap" TextWrapping="Wrap"
VerticalAlignment="Top"
HorizontalAlignment="Left"
AcceptsReturn="True" AcceptsReturn="True"
VerticalContentAlignment="Top"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto"
Text="{Binding InputTxt,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"> Text="{Binding InputTxt,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
<TextBox.InputBindings> <TextBox.InputBindings>
<KeyBinding Command="{Binding TranslateCmd}" Key="Enter" /> <KeyBinding Command="{Binding TranslateCmd}" Key="Enter" />
@ -139,51 +138,12 @@
IsReadOnly="True" IsReadOnly="True"
Margin="5" Margin="5"
FontSize="18" FontSize="18"
Width="{Binding ElementName=BorderOutput, Path=ActualWidth}"
Height="{Binding ElementName=BorderOutput, Path=Height}"
VerticalAlignment="Top"
HorizontalAlignment="Left"
TextWrapping="Wrap" TextWrapping="Wrap"
VerticalContentAlignment="Top"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto"
Text="{Binding OutputTxt}"/> Text="{Binding OutputTxt}"/>
</Border> </Border>
<!--<Button Content="复制"
Margin="0,0,10,0"
VerticalAlignment="Top"
HorizontalAlignment="Right"
Height="20"
Width="30">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
<GradientStop Color="#C0C0C0" Offset="0" />
<GradientStop Color="#787878" Offset="1" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
<GradientStop Color="LightGray" Offset="0" />
<GradientStop Color="Gray" Offset="1" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
<Button.Template>
<ControlTemplate TargetType="Button">
<Border BorderThickness="1" CornerRadius="4" Background="{TemplateBinding Background}">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" />
</Border>
</ControlTemplate>
</Button.Template>
</Button>-->
</Grid> </Grid>
</Grid> </Grid>
</Border> </Border>

@ -17,7 +17,12 @@ namespace STranslate
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
this.Activate();
this.TextBoxInput.Focus();
//if (HotKeys.InputTranslate.Conflict || HotKeys.CrosswordTranslate.Conflict || HotKeys.ScreenShotTranslate.Conflict)
//{
// MessageBox.Show("全局快捷键有冲突,请您到设置中重新设置");
//}
vm = (MainVM)DataContext; vm = (MainVM)DataContext;
} }
@ -105,6 +110,7 @@ namespace STranslate
/// <param name="e"></param> /// <param name="e"></param>
protected override void OnSourceInitialized(EventArgs e) protected override void OnSourceInitialized(EventArgs e)
{ {
base.OnSourceInitialized(e);
IntPtr handle = new WindowInteropHelper(this).Handle; IntPtr handle = new WindowInteropHelper(this).Handle;
HotKeysUtil.RegisterHotKey(handle); HotKeysUtil.RegisterHotKey(handle);
@ -192,7 +198,7 @@ namespace STranslate
/// <param name="e"></param> /// <param name="e"></param>
private void ScreenshotTranslateMenuItem_Click(object sender, RoutedEventArgs e) private void ScreenshotTranslateMenuItem_Click(object sender, RoutedEventArgs e)
{ {
MessageBox.Show("开发中"); HandyControl.Controls.MessageBox.Show("开发中");
} }
} }
} }

@ -1,6 +1,7 @@
using System; using System;
using System.Threading; using System.Threading;
using System.Windows; using System.Windows;
using System.Windows.Input;
namespace STranslate.Utils namespace STranslate.Utils
{ {
@ -18,31 +19,18 @@ namespace STranslate.Utils
//IntPtr hWnd = GetForegroundWindow(); //IntPtr hWnd = GetForegroundWindow();
//SetForegroundWindow(hWnd); //SetForegroundWindow(hWnd);
uint KEYEVENTF_KEYUP = 2; uint KEYEVENTF_KEYUP = 2;
NativeMethod.keybd_event(System.Windows.Forms.Keys.ControlKey, 0, KEYEVENTF_KEYUP, 0);
NativeMethod.keybd_event(KeyInterop.VirtualKeyFromKey(Key.LeftAlt), 0, KEYEVENTF_KEYUP, 0);
NativeMethod.keybd_event(KeyInterop.VirtualKeyFromKey(Key.RightAlt), 0, KEYEVENTF_KEYUP, 0);
NativeMethod.keybd_event(System.Windows.Forms.Keys.LWin, 0, KEYEVENTF_KEYUP, 0);
NativeMethod.keybd_event(System.Windows.Forms.Keys.RWin, 0, KEYEVENTF_KEYUP, 0);
NativeMethod.keybd_event(System.Windows.Forms.Keys.ShiftKey, 0, KEYEVENTF_KEYUP, 0);
NativeMethod.keybd_event(System.Windows.Forms.Keys.ControlKey, 0, 0, 0); NativeMethod.keybd_event(System.Windows.Forms.Keys.ControlKey, 0, 0, 0);
NativeMethod.keybd_event(System.Windows.Forms.Keys.C, 0, 0, 0); NativeMethod.keybd_event(System.Windows.Forms.Keys.C, 0, 0, 0);
NativeMethod.keybd_event(System.Windows.Forms.Keys.C, 0, KEYEVENTF_KEYUP, 0); NativeMethod.keybd_event(System.Windows.Forms.Keys.C, 0, KEYEVENTF_KEYUP, 0);
NativeMethod.keybd_event(System.Windows.Forms.Keys.ControlKey, 0, KEYEVENTF_KEYUP, 0);// 'Left Control Up NativeMethod.keybd_event(System.Windows.Forms.Keys.ControlKey, 0, KEYEVENTF_KEYUP, 0);// 'Left Control Up
} }
private static String GetDataFromClipboard()
{
try
{
if (Clipboard.ContainsText()) //检查是否存在文本
{
string res = Clipboard.GetText();
if (!string.IsNullOrWhiteSpace(res))
{
return res;
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
return null;
}
return null;
}
} }
} }

@ -15,7 +15,7 @@ namespace STranslate.Utils
public static class CrosswordTranslate public static class CrosswordTranslate
{ {
public static byte Modifiers = (byte)KeyModifiers.MOD_CTRL; public static byte Modifiers = (byte)KeyModifiers.MOD_ALT;
public static int Key = 68; public static int Key = 68;
public static String Text = "D"; public static String Text = "D";
public static bool Conflict = false; public static bool Conflict = false;

@ -39,6 +39,16 @@ namespace STranslate.Utils
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern void keybd_event(System.Windows.Forms.Keys vk, byte bScan, uint dwFlags, uint dwExtraInfo); public static extern void keybd_event(System.Windows.Forms.Keys vk, byte bScan, uint dwFlags, uint dwExtraInfo);
/// <summary>
/// 模拟触发键盘的按键
/// </summary>
/// <param name="vk">按下的键</param>
/// <param name="bScan"></param>
/// <param name="dwFlags">触发的方式0按下2抬起</param>
/// <param name="dwExtraInfo"></param>
[DllImport("user32.dll")]
public static extern void keybd_event(int vk, byte bScan, uint dwFlags, uint dwExtraInfo);
/// <summary> /// <summary>
/// 注册全局热键 /// 注册全局热键
/// </summary> /// </summary>

Loading…
Cancel
Save