Skip to content

Commit

Permalink
caps lock and punctuation added
Browse files Browse the repository at this point in the history
  • Loading branch information
DGrothe-PhD committed Sep 5, 2023
1 parent aa48019 commit 73aa999
Show file tree
Hide file tree
Showing 3 changed files with 259 additions and 50 deletions.
94 changes: 92 additions & 2 deletions T9KeyboardApp/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

140 changes: 111 additions & 29 deletions T9KeyboardApp/Form1.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
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)
{
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;
Expand All @@ -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();
Expand All @@ -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++;
Expand Down Expand Up @@ -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
}
}
}
Loading

0 comments on commit 73aa999

Please sign in to comment.