支持自定链接/快捷键

This commit is contained in:
ZouJin 2023-02-27 23:29:40 +11:00
parent f816a98f7e
commit f436ebc4f5
11 changed files with 409 additions and 5 deletions

View File

@ -149,6 +149,12 @@ namespace VPet_Simulator.Core
/// </summary>
Setting,
}
/// <summary>
/// 添加按钮
/// </summary>
/// <param name="parentMenu">按钮位置</param>
/// <param name="displayName">显示名称</param>
/// <param name="clickCallback">功能</param>
public void AddMenuButton(MenuType parentMenu,
string displayName,
Action clickCallback)

View File

@ -69,13 +69,13 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="LinePutScript, Version=1.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\LinePutScript.1.6.1\lib\net462\LinePutScript.dll</HintPath>
<HintPath>..\..\VUPSimulator\packages\LinePutScript.1.6.1\lib\net462\LinePutScript.dll</HintPath>
</Reference>
<Reference Include="Panuon.WPF, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Panuon.WPF.1.0.1\lib\net462\Panuon.WPF.dll</HintPath>
<HintPath>..\..\VUPSimulator\packages\Panuon.WPF.1.0.1\lib\net462\Panuon.WPF.dll</HintPath>
</Reference>
<Reference Include="Panuon.WPF.UI, Version=1.1.7.1, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Panuon.WPF.UI.1.1.7.2\lib\net462\Panuon.WPF.UI.dll</HintPath>
<HintPath>..\..\VUPSimulator\packages\Panuon.WPF.UI.1.1.7.2\lib\net462\Panuon.WPF.UI.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />

View File

@ -3,4 +3,7 @@
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<appSettings>
<add key="SendKeys" value="SendInput"/>
</appSettings>
</configuration>

View File

@ -1,5 +1,7 @@
using System;
using LinePutScript;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
@ -44,5 +46,22 @@ namespace VPet_Simulator.Windows
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\Save.lps", Core.Save.ToLine().ToString());
}
public void LoadDIY()
{
Main.ToolBar.MenuDIY.Items.Clear();
foreach (Sub sub in Set["diy"])
Main.ToolBar.AddMenuButton(ToolBar.MenuType.DIY, sub.Name, () => RunDIY(sub.Info));
}
public static void RunDIY(string content)
{
if(content.Contains("://") || content.Contains(@":\"))
{
Process.Start(content);
}
else
{
System.Windows.Forms.SendKeys.SendWait(content);
}
}
}
}

View File

@ -199,6 +199,9 @@ namespace VPet_Simulator.Windows
winSetting.Show();
}));
m_menu.MenuItems.Add(new MenuItem("退出桌宠", (x, y) => Close()));
LoadDIY();
notifyIcon.ContextMenu = m_menu;
notifyIcon.Icon = new System.Drawing.Icon(Application.GetResourceStream(new Uri("pack://application:,,,/vpeticon.ico")).Stream);

View File

@ -110,6 +110,9 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="WinDesign\DIYViewer.xaml.cs">
<DependentUpon>DIYViewer.xaml</DependentUpon>
</Compile>
<Compile Include="Function\CoreMOD.cs" />
<Compile Include="Function\Setting.cs" />
<Compile Include="MainWindow.cs" />
@ -129,6 +132,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="WinDesign\DIYViewer.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>

View File

@ -0,0 +1,29 @@
<UserControl x:Class="VPet_Simulator.Windows.DIYViewer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:VPet_Simulator.Windows"
xmlns:pu="clr-namespace:Panuon.WPF.UI;assembly=Panuon.WPF.UI" mc:Ignorable="d" d:DesignWidth="346"
Background="{DynamicResource SecondaryTrans4}">
<UserControl.ContextMenu>
<ContextMenu>
<MenuItem Header="置于顶层" Click="Send_Top_Click" />
<MenuItem Header="置于底层" Click="Send_Botton_Click" />
<Separator />
<MenuItem Header="快捷方式: 选择文件位置" Click="SelectFilePath_Click" />
<MenuItem Header="快捷键: 捕获按键" IsCheckable="True" Click="MenuItem_Click" />
<Separator />
<MenuItem Header="删除" Click="del_this_Click" />
</ContextMenu>
</UserControl.ContextMenu>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="8*" />
</Grid.ColumnDefinitions>
<TextBox x:Name="TextName" Margin="2" Style="{DynamicResource StandardTextBoxStyle}" pu:TextBoxHelper.Watermark="显示名称" />
<TextBox x:Name="TextContent" Margin="2" Style="{DynamicResource StandardTextBoxStyle}" pu:TextBoxHelper.Watermark="快捷键或文件位置或网站链接"
Grid.Column="1" PreviewKeyDown="TextBox_PreviewKeyDown" />
</Grid>
</UserControl>

View File

@ -0,0 +1,208 @@
using LinePutScript;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace VPet_Simulator.Windows
{
/// <summary>
/// DIYViewer.xaml 的交互逻辑
/// </summary>
public partial class DIYViewer : UserControl
{
public DIYViewer()
{
InitializeComponent();
TextName.ContextMenu = ContextMenu;
TextContent.ContextMenu = ContextMenu;
}
public DIYViewer(Sub sub)
{
InitializeComponent();
TextName.ContextMenu = ContextMenu;
TextContent.ContextMenu = ContextMenu;
TextName.Text = sub.Name;
TextContent.Text = sub.Info;
}
private bool ReadKeyPress = false;
private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (ReadKeyPress)
{
bool isshift = false;
string startxt = "";
if (TextContent.Text.EndsWith(")"))
{
isshift = true;
TextContent.Text = TextContent.Text.Substring(0, TextContent.Text.Length - 1);
startxt = TextContent.Text.Split('(')[0];
}
switch (e.Key)
{
case Key.Back:
TextContent.AppendText("{BS}");
break;
case Key.CapsLock:
case Key.Delete:
case Key.Down:
case Key.Left:
case Key.Right:
case Key.Space:
case Key.Up:
case Key.End:
case Key.Enter:
case Key.Help:
case Key.Home:
case Key.Insert:
case Key.PageUp:
case Key.PageDown:
case Key.NumLock:
case Key.Tab:
case Key.F1:
case Key.F2:
case Key.F3:
case Key.F4:
case Key.F5:
case Key.F6:
case Key.F7:
case Key.F8:
case Key.F9:
case Key.F10:
case Key.F11:
case Key.F12:
case Key.F13:
case Key.F14:
case Key.F15:
case Key.F16:
case Key.Add:
case Key.Subtract:
case Key.Multiply:
case Key.Divide:
TextContent.AppendText($"{{{e.Key.ToString().ToUpper()}}}");
break;
case Key.Escape:
TextContent.AppendText("{ESC}");
break;
case Key.PrintScreen:
TextContent.AppendText("{PRTSC}");
break;
case Key.LeftCtrl:
case Key.RightCtrl:
if (!startxt.Contains("^"))
startxt += "^";
break;
case Key.LeftAlt:
case Key.RightAlt:
case Key.System:
if (!startxt.Contains("%"))
startxt += "%";
break;
case Key.RightShift:
case Key.LeftShift:
if (!startxt.Contains("+"))
startxt += "+";
break;
case Key.OemComma:
TextContent.AppendText(",");
break;
case Key.OemPeriod:
TextContent.AppendText(".");
break;
case Key.OemQuestion:
TextContent.AppendText("/");
break;
case Key.OemMinus:
TextContent.AppendText("-");
break;
case Key.OemPlus:
TextContent.AppendText("+");
break;
case Key.Oem3:
TextContent.AppendText("`");
break;
case Key.Oem5:
TextContent.AppendText("|");
break;
case Key.LWin:
case Key.RWin:
break;
case Key.D1:
case Key.D2:
case Key.D3:
case Key.D4:
case Key.D5:
case Key.D6:
case Key.D7:
case Key.D8:
case Key.D9:
case Key.D0:
TextContent.AppendText(e.Key.ToString().Substring(1));
break;
default:
TextContent.AppendText(e.Key.ToString());
break;
}
if (isshift)
{
TextContent.Text = startxt + '(' + TextContent.Text.Split('(')[1] + ')';
}
else if (startxt.Length != 0)
{
TextContent.Text = startxt + '(' + TextContent.Text + ')';
}
e.Handled = true;
}
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
var bol = ((MenuItem)sender).IsChecked;
ReadKeyPress = bol;
TextContent.AcceptsReturn = bol;
TextContent.AcceptsTab = bol;
}
public Sub ToSub()
{
return new Sub(TextName.Text, TextContent.Text);
}
private void SelectFilePath_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog sfd = new OpenFileDialog();
sfd.Filter = "所有可执行文件|*.exe";
if (sfd.ShowDialog() == true)
{
TextContent.Text = sfd.FileName;
}
}
private void del_this_Click(object sender, RoutedEventArgs e)
{
((StackPanel)this.Parent).Children.Remove(this);
}
private void Send_Top_Click(object sender, RoutedEventArgs e)
{
((StackPanel)this.Parent).Children.Remove(this);
((StackPanel)this.Parent).Children.Insert(0, this);
}
private void Send_Botton_Click(object sender, RoutedEventArgs e)
{
((StackPanel)this.Parent).Children.Remove(this);
((StackPanel)this.Parent).Children.Add(this);
}
}
}

View File

@ -7,6 +7,11 @@
xmlns:system="clr-namespace:System;assembly=mscorlib" mc:Ignorable="d" d:DesignHeight="450" Title="设置"
Style="{DynamicResource BaseWindowXStyle}" WindowStartupLocation="CenterScreen" Closing="WindowX_Closing"
Width="400" Height="450">
<!--<pu:WindowX.Resources>
<DataTemplate x:Key="DIYDataTemplate">
</DataTemplate>
</pu:WindowX.Resources>-->
<Viewbox>
<Grid Width="400" Height="450">
<TabControl Margin="5" BorderThickness="0" pu:TabControlHelper.ItemsHeight="NaN"
@ -348,6 +353,30 @@
</Grid>
</StackPanel>
</TabItem>
<TabItem Header="自定" BorderBrush="{DynamicResource PrimaryDarker}">
<StackPanel>
<TextBlock Background="{x:Null}"
TextWrapping="Wrap">
<Run FontWeight="Bold" FontSize="16">自定义链接</Run><LineBreak />
<Run>在自定栏添加快捷方式/网页/快捷键, 可以便携启动想要的功能</Run><LineBreak/>
<Run>键盘快捷键编写方法请参考</Run> <Hyperlink Click="sendkey_click">键盘快捷键 通用注解</Hyperlink><LineBreak/>
<Run>右键进行排序/删除等操作</Run>
</TextBlock>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button pu:ButtonHelper.CornerRadius="4" Content="添加新链接" Margin="4"
Background="{DynamicResource SecondaryLight}" Padding="1" Click="DIY_ADD_Click" />
<Button pu:ButtonHelper.CornerRadius="4" Content="保存设置" Margin="4" Grid.Column="1"
Background="{DynamicResource SecondaryLight}" Padding="1" Click="DIY_Save_Click" />
</Grid>
<StackPanel x:Name="StackDIY" />
</StackPanel>
</TabItem>
<TabItem Header="诊断" BorderBrush="{DynamicResource PrimaryDarker}">
<StackPanel>

View File

@ -1,4 +1,5 @@
using Panuon.WPF.UI;
using LinePutScript;
using Panuon.WPF.UI;
using Steamworks.Ugc;
using System;
using System.Collections.Generic;
@ -89,6 +90,9 @@ namespace VPet_Simulator.Windows
}
}
foreach (Sub sub in mw.Set["diy"])
StackDIY.Children.Add(new DIYViewer(sub));
#if X64
GameVerison.Content = $"游戏版本v{mw.Verison} x64";
#else
@ -524,6 +528,10 @@ namespace VPet_Simulator.Windows
{
Process.Start("https://jq.qq.com/?_wv=1027&k=zmeWNHyI");
}
private void sendkey_click(object sender, RoutedEventArgs e)
{
Process.Start("https://www.exlb.net/SendKeys");
}
#endregion
private void sDesktopAlignment_Checked_1(object sender, RoutedEventArgs e)
{
@ -631,5 +639,20 @@ namespace VPet_Simulator.Windows
return;
mw.Core.Save.Name = TextBoxPetName.Text;
}
private void DIY_ADD_Click(object sender, RoutedEventArgs e)
{
StackDIY.Children.Add(new DIYViewer());
}
private void DIY_Save_Click(object sender, RoutedEventArgs e)
{
mw.Set["diy"].Clear();
foreach (DIYViewer dv in StackDIY.Children)
{
mw.Set["diy"].Add(dv.ToSub());
}
mw.LoadDIY();
}
}
}

View File

@ -0,0 +1,77 @@
# 键盘快捷键 通用注解
## 编写方法
每个键由一个或多个字符表示。 若要指定单个键盘字符,请使用字符本身。 例如,若要表示字母 A请将字符串“A”传递给该方法。 若要表示多个字符,请将每个附加字符追加到前面的字符。 若要表示字母 A、B 和 C请将参数指定为“ABC”。
加号 (+) 、插入符号 ^ () 、百分比符号 (%) 、平铺 (~) ,括号 () 具有特殊含义. 若要指定其中一个字符,请将它括在大括号 ({}) 中。 例如,若要指定加号,请使用“{+}”。 若要指定大括号字符,请使用“{{}”和“{}}”
## 特殊按键
若要指定在按下键(如 ENTER 或 TAB时未显示的字符以及表示操作而不是字符的键请使用下表中的代码。
| 键 | 代码 |
| :------------ | :------------------------- |
| Backspace | {BACKSPACE}、{BS}或 {BKSP} |
| BREAK | {BREAK} |
| Caps Lock | {CAPSLOCK} |
| DEL 或 DELETE | {DELETE} 或 {DEL} |
| 向下键 | {DOWN} |
| End | {END} |
| Enter | {ENTER}或 ~ |
| ESC | {ESC} |
| HELP | {HELP} |
| Home | {HOME} |
| INS 或 INSERT | {INSERT} 或 {INS} |
| 向左键 | {LEFT} |
| Num Lock | {NUMLOCK} |
| Page Down | {PGDN} |
| Page Up | {PGUP} |
| 打印屏幕 | {PRTSC} (保留供将来使用) |
| 向右键 | {RIGHT} |
| Scroll Lock | {SCROLLLOCK} |
| Tab | {TAB} |
| 向上键 | {UP} |
| F1 | {F1} |
| F2 | {F2} |
| F3 | {F3} |
| F4 | {F4} |
| F5 | {F5} |
| F6 | {F6} |
| F7 | {F7} |
| F8 | {F8} |
| F9 | {F9} |
| F10 | {F10} |
| F11 | {F11} |
| F12 | {F12} |
| F13 | {F13} |
| F14 | {F14} |
| F15 | {F15} |
| F16 | {F16} |
| 小键盘加 | {ADD} |
| 小键盘减 | {SUBTRACT} |
| 小键盘乘 | {MULTIPLY} |
| 小键盘除 | {DIVIDE} |
## 键盘转换键
若要指定键与 SHIFT、Ctrl 和 ALT 键的任意组合,请在键代码前面加上以下一个或多个代码。
| 键 | 代码 |
| :---- | :--- |
| SHIFT | + |
| Ctrl | ^ |
| ALT | % |
## 同时按下
若要指定应按住 SHIFT、Ctrl 和 ALT 的任意组合,同时按下其他几个键,请将这些键的代码括在括号中。 例如,若要指定在按下 E 和 C 时按住 SHIFT请使用“+ (EC) ”。 若要指定在按下 E 时按住 SHIFT后跟 C 而不使用 SHIFT请使用“+EC”。
## 重复按下
若要指定重复键,请使用 {key number} 格式。 必须在键和数字之间放置空格。 例如,{LEFT 42} 表示按向左键 42 次; {h 10} 表示按 H 10 次。
## 来源与更多
键盘按键功能使用的是 SendKeys.Send(String)
如需详细了解该功能,可以前往 [微软文档 SendKeys.Send(String) 方法](https://learn.microsoft.com/zh-cn/dotnet/api/system.windows.forms.sendkeys.send?view=windowsdesktop-7.0#--) 查看