diff --git a/T9KeyboardApp/Form1.Designer.cs b/T9KeyboardApp/Form1.Designer.cs index fdd99ea..ced4cbe 100644 --- a/T9KeyboardApp/Form1.Designer.cs +++ b/T9KeyboardApp/Form1.Designer.cs @@ -41,20 +41,26 @@ private void InitializeComponent() button9 = new Button(); button10 = new Button(); timerKeysWait = new System.Windows.Forms.Timer(components); + buttonModeSwitch = new Button(); + button12 = new Button(); + button13 = new Button(); + button14 = new Button(); + button15 = new Button(); + button16 = new Button(); SuspendLayout(); // // textBox1 // textBox1.BackColor = SystemColors.ControlLight; textBox1.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); - textBox1.Location = new Point(374, 16); + textBox1.Location = new Point(463, 16); textBox1.Margin = new Padding(4, 5, 4, 5); textBox1.MaximumSize = new Size(1300, 624); textBox1.MinimumSize = new Size(10, 12); textBox1.Multiline = true; textBox1.Name = "textBox1"; textBox1.ReadOnly = true; - textBox1.Size = new Size(847, 583); + textBox1.Size = new Size(758, 583); textBox1.TabIndex = 0; textBox1.KeyPress += Form1_KeyPress; textBox1.KeyUp += Form1_KeyUp; @@ -184,11 +190,89 @@ private void InitializeComponent() timerKeysWait.Interval = 150; timerKeysWait.Tick += TimerKeysWait_Tick; // + // buttonModeSwitch + // + buttonModeSwitch.Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Regular, GraphicsUnit.Point); + buttonModeSwitch.Location = new Point(249, 489); + buttonModeSwitch.Margin = new Padding(4, 5, 4, 5); + buttonModeSwitch.Name = "buttonModeSwitch"; + buttonModeSwitch.Size = new Size(117, 111); + buttonModeSwitch.TabIndex = 11; + buttonModeSwitch.Text = "#\r\nAa123"; + buttonModeSwitch.UseVisualStyleBackColor = true; + buttonModeSwitch.Click += buttonModeSwitch_Click; + // + // button12 + // + button12.Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Regular, GraphicsUnit.Point); + button12.Location = new Point(374, 365); + button12.Margin = new Padding(4, 5, 4, 5); + button12.Name = "button12"; + button12.Size = new Size(69, 111); + button12.TabIndex = 12; + button12.Text = "+"; + button12.UseVisualStyleBackColor = true; + button12.Click += ButtonClick; + // + // button13 + // + button13.Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Regular, GraphicsUnit.Point); + button13.Location = new Point(374, 245); + button13.Margin = new Padding(4, 5, 4, 5); + button13.Name = "button13"; + button13.Size = new Size(69, 111); + button13.TabIndex = 13; + button13.Text = "-"; + button13.UseVisualStyleBackColor = true; + button13.Click += ButtonClick; + // + // button14 + // + button14.Font = new Font("Microsoft Sans Serif", 24F, FontStyle.Regular, GraphicsUnit.Point); + button14.Location = new Point(-1, 489); + button14.Margin = new Padding(4, 5, 4, 5); + button14.Name = "button14"; + button14.Size = new Size(117, 110); + button14.TabIndex = 14; + button14.Text = "*"; + button14.UseVisualStyleBackColor = true; + button14.Click += ButtonClick; + // + // button15 + // + button15.Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Regular, GraphicsUnit.Point); + button15.Location = new Point(374, 125); + button15.Margin = new Padding(4, 5, 4, 5); + button15.Name = "button15"; + button15.Size = new Size(69, 110); + button15.TabIndex = 15; + button15.Text = "/"; + button15.UseVisualStyleBackColor = true; + button15.Click += ButtonClick; + // + // button16 + // + button16.Font = new Font("Microsoft Sans Serif", 24F, FontStyle.Regular, GraphicsUnit.Point); + button16.Location = new Point(374, 490); + button16.Margin = new Padding(4, 5, 4, 5); + button16.Name = "button16"; + button16.Size = new Size(69, 111); + button16.TabIndex = 16; + button16.Text = ","; + button16.UseVisualStyleBackColor = true; + button16.Click += ButtonClick; + // // Form1 // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(1230, 629); + Controls.Add(button16); + Controls.Add(button15); + Controls.Add(button14); + Controls.Add(button13); + Controls.Add(button12); + Controls.Add(buttonModeSwitch); Controls.Add(button10); Controls.Add(button9); Controls.Add(button8); @@ -223,6 +307,12 @@ private void InitializeComponent() private Button button9; private Button button10; private System.Windows.Forms.Timer timerKeysWait; + private Button buttonModeSwitch; + private Button button12; + private Button button13; + private Button button14; + private Button button15; + private Button button16; } } diff --git a/T9KeyboardApp/Form1.cs b/T9KeyboardApp/Form1.cs index da150ad..c8884da 100644 --- a/T9KeyboardApp/Form1.cs +++ b/T9KeyboardApp/Form1.cs @@ -1,10 +1,18 @@ +using System; + namespace T9KeyboardApp { public partial class Form1 : Form { + public Mode EntryMode { get; set; } + int counter = 0; + bool timerIsRunning = false; + Button? buttonPressed = null; + public Form1() { InitializeComponent(); + EntryMode = Mode.Normal; } private void Button1_Click(object sender, EventArgs e) @@ -12,17 +20,27 @@ private void Button1_Click(object sender, EventArgs e) textBox1.Text += " "; } +#region keyhandler + private void Form1_KeyDown(object sender, KeyEventArgs e) + { + ; + } + private void Form1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == ' ') { textBox1.Text += " "; } - else if (int.TryParse("" + e.KeyChar, out int _)) + else if (e.KeyChar == '#') { - foreach (Button b in Controls) + SwitchMode(); + } + else // if (int.TryParse("" + e.KeyChar, out int _)) + { + foreach (var b in Controls) { - if (b.Text[0] == e.KeyChar) + if (b is Button && ((Button)b).Text[0] == e.KeyChar) { ButtonClick(b, new EventArgs()); break; @@ -31,18 +49,45 @@ private void Form1_KeyPress(object sender, KeyPressEventArgs e) } } - bool timerIsRunning = false; - Button? buttonPressed = null; + private void Form1_KeyUp(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter) + { + textBox1.Text += Environment.NewLine; + } + else if (e.KeyCode == Keys.F3) + { + Clipboard.SetText(textBox1.Text); + } + else if (e.KeyCode == Keys.F6) + { + textBox1.Text = ""; + } + else if (e.KeyCode == Keys.Back) + { + textBox1.Text = textBox1.Text.Backspace(); + } + } +#endregion private void TypeLetter() { + char? c = buttonPressed?.Text[0]; if (buttonPressed != null - && int.TryParse("" + buttonPressed.Text[0], out int index) + && int.TryParse("" + c, out int index) ) - textBox1.Text += Buttons.buttons[index].Key(); + textBox1.Text += Buttons.buttons[index].Key(EntryMode); + else + textBox1.Text += OperatorWrite(c); + + if (EntryMode == Mode.Capital) + { + EntryMode = Mode.Normal; + } } private void ButtonClick(object sender, EventArgs e) { + //((Button)sender).BackColor = Color.White; if (buttonPressed != sender as Button) { if (timerIsRunning) StopTimer(); @@ -56,9 +101,57 @@ private void ButtonClick(object sender, EventArgs e) buttonPressed = sender as Button; if (int.TryParse("" + buttonPressed?.Text[0], out int index)) Buttons.buttons[index].Hit(); + else OperatorButton(buttonPressed?.Text[0]); + + textBox1.Select(); + } + + private void OperatorButton(char? name) + { + if (name == null) + return; + switch (name) + { + case ',': + Buttons.buttons[10].Hit(); + break; + case '-': + Buttons.buttons[11].Hit(); + break; + case '/': + Buttons.buttons[12].Hit(); + break; + case '*': + Buttons.buttons[13].Hit(); + break; + case '+': + Buttons.buttons[14].Hit(); + break; + } + } + + private char? OperatorWrite(char? name) + { + char? value = null; + if (name == null) + return value; + switch (name) + { + case ',': + return Buttons.buttons[10].Key(EntryMode); + case '-': + return Buttons.buttons[11].Key(EntryMode); + case '/': + return Buttons.buttons[12].Key(EntryMode); + case '*': + return Buttons.buttons[13].Key(EntryMode); + case '+': + return Buttons.buttons[14].Key(EntryMode); + default: + return value; + } } - int counter = 0; private void TimerKeysWait_Tick(object sender, EventArgs e) { counter++; @@ -86,28 +179,17 @@ private void StopTimer() textBox1.BackColor = Color.Moccasin; } - private void Form1_KeyUp(object sender, KeyEventArgs e) + + private void buttonModeSwitch_Click(object sender, EventArgs e) { - if(e.KeyCode == Keys.Enter) - { - textBox1.Text += Environment.NewLine; - } - else if (e.KeyCode == Keys.F3) - { - Clipboard.SetText(textBox1.Text); - } - else if (e.KeyCode == Keys.Escape) - { - Close(); - } - else if (e.KeyCode == Keys.F6) - { - textBox1.Text = ""; - } - else if (e.KeyCode == Keys.Back) - { - textBox1.Text = textBox1.Text.Backspace(); - } + SwitchMode(); + textBox1.Select(); + } + + private void SwitchMode() + { + EntryMode = (Mode)((int)(EntryMode + 1) % 4); + //colors } } } diff --git a/T9KeyboardApp/Utils.cs b/T9KeyboardApp/Utils.cs index 9cdd943..6a63870 100644 --- a/T9KeyboardApp/Utils.cs +++ b/T9KeyboardApp/Utils.cs @@ -5,27 +5,35 @@ namespace T9KeyboardApp { + public enum Mode + { + Normal, + Capital, + CapsLock, + Numeric + } public static class Extensions { public static String Backspace(this String str) { - if(String.IsNullOrEmpty(str)) return str; + if (String.IsNullOrEmpty(str)) return str; return str[..^1]; } } public class ButtonKey { - //prior to C# 8 private readonly List keys; - private readonly byte number; + private readonly string name; + public string Name { get => name; } private byte hittimes = 0; - public ButtonKey(byte number, params char[] chars) { + public ButtonKey(byte number, params char[] chars) + { keys = new List(); foreach (char c in chars) { keys.Add(c); } - this.number = number; + this.name = "" + number; this.hittimes = 0; } @@ -36,21 +44,44 @@ public ButtonKey(byte number, string chars) { keys.Add(c); } - this.number = number; + this.name = "" + number; + } + + public ButtonKey(string name, string chars) + { + keys = new List(); + foreach (char c in chars) + { + keys.Add(c); + } + this.name = name; } public char Value() { - if (hittimes < 1 || hittimes - 1 > keys.Count) + if (hittimes < 1 || hittimes > keys.Count) { - return number.ToString()[0]; + return name.ToString()[0]; } - return keys[hittimes-1]; + return keys[hittimes - 1]; } - public char Key() + public char? Key(Mode entryMode = Mode.Normal) { - char c = Value(); + char? c = null; + switch (entryMode) + { + case Mode.Normal: + c = Value(); + break; + case Mode.Numeric: + c = Name[0]; + break; + default: + c = char.ToUpper(Value()); + break; + } + Reset(); return c; } @@ -61,18 +92,24 @@ public char Key() public static class Buttons { - public static readonly ButtonKey[] buttons = + public static readonly List buttons = + new() { - new ButtonKey(0, "0"), - new ButtonKey(1, " 1"), - new ButtonKey(2, "abc2ä"), - new ButtonKey(3, "def3"), + new ButtonKey(0, "0@°%[]"), + new ButtonKey(1, " 1\"()"), + new ButtonKey(2, "abcäç2"), + new ButtonKey(3, "deféèê3"), new ButtonKey(4, "ghi4"), new ButtonKey(5, "jkl5"), - new ButtonKey(6, "mnoö6"), + new ButtonKey(6, "mnoöô6"), new ButtonKey(7, "pqrsß7"), - new ButtonKey(8, "tuvü8"), - new ButtonKey(9, "wxyz9"), + new ButtonKey(8, "tuvüû8"), + new ButtonKey(9, "wxyz$9"), + new ButtonKey(",", ",.!?:;"), + new ButtonKey("-", "-_=<>"), + new ButtonKey("/", "/\\|"), + new ButtonKey("*", "*^{}"), + new ButtonKey("+", "+&"), }; }