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; namespace DyeingComputer.KEY { /// /// TouchKeyboard.xaml 的交互逻辑 /// public partial class TouchKeyboard : Window { private bool isShiftActive = false; private bool isSymbolActive = false; public string KeyValue; 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 Symbol_Click(object sender, RoutedEventArgs e) { isSymbolActive = !isSymbolActive; // 这里可以添加切换符号键盘的逻辑 StatusTextBlock.Text = isSymbolActive ? "符号模式" : "字母模式"; } private void Space_Click(object sender, RoutedEventArgs e) { PreviewTextBox.Text += " "; } 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) { KeyValue = PreviewTextBox.Text; this.Close(); // PreviewTextBox.Text += Environment.NewLine; } private void Hide_Click(object sender, RoutedEventArgs e) { this.Close(); } private void UpdateButtonAppearance() { // 更新Shift按钮的外观以反映当前状态 if (isShiftActive) { ShiftButton.Background = new SolidColorBrush(Colors.LightBlue); } else { ShiftButton.Background = new SolidColorBrush(Color.FromRgb(224, 224, 224)); } } } }