You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
3.3 KiB
116 lines
3.3 KiB
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.Shapes;
|
|
using static DyeingComputer.KEY.TouchKeyboardNumeral;
|
|
|
|
namespace DyeingComputer.KEY
|
|
{
|
|
/// <summary>
|
|
/// TouchKeyboard.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class TouchKeyboard : Window
|
|
{
|
|
private bool isShiftActive = false;
|
|
public string KeyValue;
|
|
public event EventHandler<KeyPressedEventArgs> KeyPressed;
|
|
|
|
public TouchKeyboard()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void KeyButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
Button button = sender as Button;
|
|
if (button != null)
|
|
{
|
|
string key = button.Content.ToString();
|
|
|
|
if (key.Length == 1 && char.IsLetter(key[0]))
|
|
{
|
|
key = isShiftActive ? key.ToUpper() : key.ToLower();
|
|
}
|
|
|
|
PreviewTextBox.Text += key;
|
|
|
|
// 输入后关闭Shift状态
|
|
if (isShiftActive)
|
|
{
|
|
isShiftActive = false;
|
|
UpdateButtonAppearance();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Shift_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
isShiftActive = !isShiftActive;
|
|
UpdateButtonAppearance();
|
|
}
|
|
|
|
private void Backspace_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (!string.IsNullOrEmpty(PreviewTextBox.Text))
|
|
{
|
|
PreviewTextBox.Text = PreviewTextBox.Text.Substring(0, PreviewTextBox.Text.Length - 1);
|
|
}
|
|
}
|
|
|
|
private void Enter_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
// 触发回车事件
|
|
KeyPressed?.Invoke(this, new KeyPressedEventArgs(KeyType.Enter, PreviewTextBox.Text));
|
|
|
|
this.Close();
|
|
// PreviewTextBox.Text += Environment.NewLine;
|
|
}
|
|
|
|
private void Hide_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
KeyPressed?.Invoke(this, new KeyPressedEventArgs(KeyType.Hide, ""));
|
|
this.Close();
|
|
}
|
|
|
|
private void UpdateButtonAppearance()
|
|
{
|
|
// 更新Shift按钮的外观以反映当前状态
|
|
if (isShiftActive)
|
|
{
|
|
ShiftButton.Background = new SolidColorBrush(Colors.LightBlue);
|
|
}
|
|
else
|
|
{
|
|
ShiftButton.Background = new SolidColorBrush(Color.FromRgb(224, 224, 224));
|
|
}
|
|
}
|
|
|
|
public class KeyPressedEventArgs : EventArgs
|
|
{
|
|
public KeyType KeyType { get; }
|
|
public string KeyValue { get; }
|
|
|
|
public KeyPressedEventArgs(KeyType keyType, string keyValue)
|
|
{
|
|
KeyType = keyType;
|
|
KeyValue = keyValue;
|
|
}
|
|
}
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
// 初始化为默认模式
|
|
// SetKeyboardMode(KeyboardMode.Default);
|
|
PreviewTextBox.Text = null;
|
|
}
|
|
}
|
|
|
|
}
|
|
|