From aa48019a10152a3336ddb6dd0623391c49f597a8 Mon Sep 17 00:00:00 2001 From: DGrothe-PhD Date: Tue, 5 Sep 2023 12:44:10 +0200 Subject: [PATCH] initial commit --- .github/ISSUE_TEMPLATE/bug_report.md | 31 +++ .github/ISSUE_TEMPLATE/feature_request.md | 20 ++ .github/ISSUE_TEMPLATE/question.md | 17 ++ .github/ISSUE_TEMPLATE/test.md | 20 ++ .github/labeler.yml | 14 ++ .github/workflows/dotnet.yml | 40 ++++ .github/workflows/labeler.yml | 20 ++ .gitignore | 7 + T9KeyboardApp/Form1.Designer.cs | 228 ++++++++++++++++++++++ T9KeyboardApp/Form1.cs | 113 +++++++++++ T9KeyboardApp/Form1.resx | 123 ++++++++++++ T9KeyboardApp/Program.cs | 17 ++ T9KeyboardApp/T9KeyboardApp.csproj | 11 ++ T9KeyboardApp/T9KeyboardApp.sln | 25 +++ T9KeyboardApp/Utils.cs | 79 ++++++++ 15 files changed, 765 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/ISSUE_TEMPLATE/question.md create mode 100644 .github/ISSUE_TEMPLATE/test.md create mode 100644 .github/labeler.yml create mode 100644 .github/workflows/dotnet.yml create mode 100644 .github/workflows/labeler.yml create mode 100644 .gitignore create mode 100644 T9KeyboardApp/Form1.Designer.cs create mode 100644 T9KeyboardApp/Form1.cs create mode 100644 T9KeyboardApp/Form1.resx create mode 100644 T9KeyboardApp/Program.cs create mode 100644 T9KeyboardApp/T9KeyboardApp.csproj create mode 100644 T9KeyboardApp/T9KeyboardApp.sln create mode 100644 T9KeyboardApp/Utils.cs diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..3b1e47f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,31 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Version [e.g. 1.0.0-beta] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..11fc491 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md new file mode 100644 index 0000000..f777acd --- /dev/null +++ b/.github/ISSUE_TEMPLATE/question.md @@ -0,0 +1,17 @@ +--- +name: Question +about: Ask a question. +title: '' +labels: question +assignees: '' + +--- + +**What is your question? Please describe.** +A clear and concise description of what you + +**Context** +A clear and concise description of the application function you were using, what you were trying to achieve, and what you are trying to figure out or what you do not understand. + +**Additional context** +Add any other relevant context or screenshots here. diff --git a/.github/ISSUE_TEMPLATE/test.md b/.github/ISSUE_TEMPLATE/test.md new file mode 100644 index 0000000..a1a752f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/test.md @@ -0,0 +1,20 @@ +--- +name: Test +about: Test to be done - Something to test for. +title: "[TEST]" +labels: testcase +assignees: '' + +--- + +** Scenario to test for** + + +** Test steps** + + +** Affected method (optional)** + + +** Context as necessary** +e. g. the screen or operating system diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 0000000..2bbf120 --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,14 @@ +deployment: +- any: ['.github/workflows/*.yml', '!labeler.yml'] + +project: +- '*.sln' +- '*.proj' + +design: +- 'T9*/Resources/*.png' +- './**/*Designer.cs' + +testcase: +- 'T9*.Tests/*.cs' +- './**/*Test*.cs' diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml new file mode 100644 index 0000000..807600e --- /dev/null +++ b/.github/workflows/dotnet.yml @@ -0,0 +1,40 @@ +# This workflow will build a .NET project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net + +name: .NET + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: windows-latest + defaults: + run: + working-directory: T9KeyboardApp + + steps: + - uses: actions/checkout@v3 + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 6.0.x + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --no-restore +# - name: Test +# working-directory: T9KeyboardApp.Tests +# run: dotnet test T9KeyboardApp.Tests.csproj --logger "trx;logfilename=testResults.trx" --results-directory TestResults +# - name: Test Report +# uses: dorny/test-reporter@v1 +# if: always() +# with: +# name: DotNET Tests +# path: "T9KeyboardApp.Tests/**/test*Results*.trx" +# reporter: dotnet-trx +# fail-on-error: true diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml new file mode 100644 index 0000000..f19beae --- /dev/null +++ b/.github/workflows/labeler.yml @@ -0,0 +1,20 @@ +# This workflow will triage pull requests and apply a label based on the +# paths that are modified in the pull request. +# +# To use this workflow, you will need to set up a .github/labeler.yml +# file with configuration. For more information, see: +# https://github.com/actions/labeler + +name: Labeler +on: [push, pull_request] + +jobs: + label: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + steps: + - uses: actions/labeler@v4 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ce47d29 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +bin/ +obj/ +.vs/ +*.user +src/Properties/PublishProfiles/ +src/Properties/Settings.Designer.cs +src/Properties/Settings.settings \ No newline at end of file diff --git a/T9KeyboardApp/Form1.Designer.cs b/T9KeyboardApp/Form1.Designer.cs new file mode 100644 index 0000000..fdd99ea --- /dev/null +++ b/T9KeyboardApp/Form1.Designer.cs @@ -0,0 +1,228 @@ +namespace T9KeyboardApp +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + textBox1 = new TextBox(); + button1 = new Button(); + button2 = new Button(); + button3 = new Button(); + button4 = new Button(); + button5 = new Button(); + button6 = new Button(); + button7 = new Button(); + button8 = new Button(); + button9 = new Button(); + button10 = new Button(); + timerKeysWait = new System.Windows.Forms.Timer(components); + SuspendLayout(); + // + // textBox1 + // + textBox1.BackColor = SystemColors.ControlLight; + textBox1.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); + textBox1.Location = new Point(374, 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.TabIndex = 0; + textBox1.KeyPress += Form1_KeyPress; + textBox1.KeyUp += Form1_KeyUp; + // + // button1 + // + button1.Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Regular, GraphicsUnit.Point); + button1.Location = new Point(-1, 125); + button1.Margin = new Padding(4, 5, 4, 5); + button1.Name = "button1"; + button1.Size = new Size(117, 111); + button1.TabIndex = 1; + button1.Text = "1\r\no_o"; + button1.UseVisualStyleBackColor = true; + button1.Click += Button1_Click; + // + // button2 + // + button2.Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Regular, GraphicsUnit.Point); + button2.Location = new Point(124, 125); + button2.Margin = new Padding(4, 5, 4, 5); + button2.Name = "button2"; + button2.Size = new Size(117, 111); + button2.TabIndex = 2; + button2.Text = "2\r\nABC"; + button2.UseVisualStyleBackColor = true; + button2.Click += ButtonClick; + // + // button3 + // + button3.Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Regular, GraphicsUnit.Point); + button3.Location = new Point(249, 125); + button3.Margin = new Padding(4, 5, 4, 5); + button3.Name = "button3"; + button3.Size = new Size(117, 111); + button3.TabIndex = 3; + button3.Text = "3\r\nDEF"; + button3.UseVisualStyleBackColor = true; + button3.Click += ButtonClick; + // + // button4 + // + button4.Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Regular, GraphicsUnit.Point); + button4.Location = new Point(-1, 245); + button4.Margin = new Padding(4, 5, 4, 5); + button4.Name = "button4"; + button4.Size = new Size(117, 111); + button4.TabIndex = 4; + button4.Text = "4\r\nGHI"; + button4.UseVisualStyleBackColor = true; + button4.Click += ButtonClick; + // + // button5 + // + button5.Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Regular, GraphicsUnit.Point); + button5.Location = new Point(124, 245); + button5.Margin = new Padding(4, 5, 4, 5); + button5.Name = "button5"; + button5.Size = new Size(117, 111); + button5.TabIndex = 5; + button5.Text = "5\r\nJKL"; + button5.UseVisualStyleBackColor = true; + button5.Click += ButtonClick; + // + // button6 + // + button6.Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Regular, GraphicsUnit.Point); + button6.Location = new Point(249, 245); + button6.Margin = new Padding(4, 5, 4, 5); + button6.Name = "button6"; + button6.Size = new Size(117, 111); + button6.TabIndex = 6; + button6.Text = "6\r\nMNO"; + button6.UseVisualStyleBackColor = true; + button6.Click += ButtonClick; + // + // button7 + // + button7.Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Regular, GraphicsUnit.Point); + button7.Location = new Point(-1, 365); + button7.Margin = new Padding(4, 5, 4, 5); + button7.Name = "button7"; + button7.Size = new Size(117, 111); + button7.TabIndex = 7; + button7.Text = "7\r\nPQRS"; + button7.UseVisualStyleBackColor = true; + button7.Click += ButtonClick; + // + // button8 + // + button8.Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Regular, GraphicsUnit.Point); + button8.Location = new Point(124, 365); + button8.Margin = new Padding(4, 5, 4, 5); + button8.Name = "button8"; + button8.Size = new Size(117, 111); + button8.TabIndex = 8; + button8.Text = "8\r\nTUV"; + button8.UseVisualStyleBackColor = true; + button8.Click += ButtonClick; + // + // button9 + // + button9.Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Regular, GraphicsUnit.Point); + button9.Location = new Point(249, 365); + button9.Margin = new Padding(4, 5, 4, 5); + button9.Name = "button9"; + button9.Size = new Size(117, 111); + button9.TabIndex = 9; + button9.Text = "9\r\nWXYZ"; + button9.UseVisualStyleBackColor = true; + button9.Click += ButtonClick; + // + // button10 + // + button10.Font = new Font("Microsoft Sans Serif", 13.8F, FontStyle.Regular, GraphicsUnit.Point); + button10.Location = new Point(124, 489); + button10.Margin = new Padding(4, 5, 4, 5); + button10.Name = "button10"; + button10.Size = new Size(117, 111); + button10.TabIndex = 10; + button10.Text = "0"; + button10.UseVisualStyleBackColor = true; + button10.Click += ButtonClick; + // + // timerKeysWait + // + timerKeysWait.Interval = 150; + timerKeysWait.Tick += TimerKeysWait_Tick; + // + // Form1 + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1230, 629); + Controls.Add(button10); + Controls.Add(button9); + Controls.Add(button8); + Controls.Add(button7); + Controls.Add(button6); + Controls.Add(button5); + Controls.Add(button4); + Controls.Add(button3); + Controls.Add(button2); + Controls.Add(button1); + Controls.Add(textBox1); + Margin = new Padding(4, 5, 4, 5); + Name = "Form1"; + Text = "T9 Dictionary"; + KeyPress += Form1_KeyPress; + KeyUp += Form1_KeyUp; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBox1; + private Button button1; + private Button button2; + private Button button3; + private Button button4; + private Button button5; + private Button button6; + private Button button7; + private Button button8; + private Button button9; + private Button button10; + private System.Windows.Forms.Timer timerKeysWait; + } +} + diff --git a/T9KeyboardApp/Form1.cs b/T9KeyboardApp/Form1.cs new file mode 100644 index 0000000..da150ad --- /dev/null +++ b/T9KeyboardApp/Form1.cs @@ -0,0 +1,113 @@ +namespace T9KeyboardApp +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + private void Button1_Click(object sender, EventArgs e) + { + textBox1.Text += " "; + } + + private void Form1_KeyPress(object sender, KeyPressEventArgs e) + { + if (e.KeyChar == ' ') + { + textBox1.Text += " "; + } + else if (int.TryParse("" + e.KeyChar, out int _)) + { + foreach (Button b in Controls) + { + if (b.Text[0] == e.KeyChar) + { + ButtonClick(b, new EventArgs()); + break; + } + } + } + } + + bool timerIsRunning = false; + Button? buttonPressed = null; + private void TypeLetter() + { + if (buttonPressed != null + && int.TryParse("" + buttonPressed.Text[0], out int index) + ) + textBox1.Text += Buttons.buttons[index].Key(); + } + + private void ButtonClick(object sender, EventArgs e) + { + if (buttonPressed != sender as Button) + { + if (timerIsRunning) StopTimer(); + StartTimer(); + } + if (!timerIsRunning) + { + StartTimer(); + } + + buttonPressed = sender as Button; + if (int.TryParse("" + buttonPressed?.Text[0], out int index)) + Buttons.buttons[index].Hit(); + } + + int counter = 0; + private void TimerKeysWait_Tick(object sender, EventArgs e) + { + counter++; + + if (counter > 6) + { + StopTimer(); + } + } + + private void StartTimer() + { + counter = 0; + timerKeysWait.Start(); + timerIsRunning = true; + textBox1.BackColor = Color.IndianRed; + } + private void StopTimer() + { + textBox1.BackColor = Color.LawnGreen; + timerKeysWait.Stop(); + counter = 0; + timerIsRunning = false; + TypeLetter(); + textBox1.BackColor = Color.Moccasin; + } + + 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.Escape) + { + Close(); + } + else if (e.KeyCode == Keys.F6) + { + textBox1.Text = ""; + } + else if (e.KeyCode == Keys.Back) + { + textBox1.Text = textBox1.Text.Backspace(); + } + } + } +} diff --git a/T9KeyboardApp/Form1.resx b/T9KeyboardApp/Form1.resx new file mode 100644 index 0000000..774dcc2 --- /dev/null +++ b/T9KeyboardApp/Form1.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/T9KeyboardApp/Program.cs b/T9KeyboardApp/Program.cs new file mode 100644 index 0000000..9249bf0 --- /dev/null +++ b/T9KeyboardApp/Program.cs @@ -0,0 +1,17 @@ +namespace T9KeyboardApp +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Form1()); + } + } +} \ No newline at end of file diff --git a/T9KeyboardApp/T9KeyboardApp.csproj b/T9KeyboardApp/T9KeyboardApp.csproj new file mode 100644 index 0000000..b57c89e --- /dev/null +++ b/T9KeyboardApp/T9KeyboardApp.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + \ No newline at end of file diff --git a/T9KeyboardApp/T9KeyboardApp.sln b/T9KeyboardApp/T9KeyboardApp.sln new file mode 100644 index 0000000..f8323b4 --- /dev/null +++ b/T9KeyboardApp/T9KeyboardApp.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34009.444 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "T9KeyboardApp", "T9KeyboardApp.csproj", "{AF2433B9-E9F9-4E53-8541-A13CCBF8A3CD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AF2433B9-E9F9-4E53-8541-A13CCBF8A3CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AF2433B9-E9F9-4E53-8541-A13CCBF8A3CD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AF2433B9-E9F9-4E53-8541-A13CCBF8A3CD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AF2433B9-E9F9-4E53-8541-A13CCBF8A3CD}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0BC0F29F-2880-4D85-B039-288D4F5FB0C9} + EndGlobalSection +EndGlobal diff --git a/T9KeyboardApp/Utils.cs b/T9KeyboardApp/Utils.cs new file mode 100644 index 0000000..9cdd943 --- /dev/null +++ b/T9KeyboardApp/Utils.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace T9KeyboardApp +{ + public static class Extensions + { + public static String Backspace(this String 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 byte hittimes = 0; + public ButtonKey(byte number, params char[] chars) { + keys = new List(); + foreach (char c in chars) + { + keys.Add(c); + } + this.number = number; + this.hittimes = 0; + } + + public ButtonKey(byte number, string chars) + { + keys = new List(); + foreach (char c in chars) + { + keys.Add(c); + } + this.number = number; + } + + public char Value() + { + if (hittimes < 1 || hittimes - 1 > keys.Count) + { + return number.ToString()[0]; + } + return keys[hittimes-1]; + } + + public char Key() + { + char c = Value(); + Reset(); + return c; + } + + public void Hit() { hittimes++; } + private void Reset() { hittimes = 0; } + } + + public static class Buttons + { + public static readonly ButtonKey[] buttons = + { + new ButtonKey(0, "0"), + new ButtonKey(1, " 1"), + new ButtonKey(2, "abc2ä"), + new ButtonKey(3, "def3"), + new ButtonKey(4, "ghi4"), + new ButtonKey(5, "jkl5"), + new ButtonKey(6, "mnoö6"), + new ButtonKey(7, "pqrsß7"), + new ButtonKey(8, "tuvü8"), + new ButtonKey(9, "wxyz9"), + }; + + } +}