Skip to content

Instantly share code, notes, and snippets.

@tuansoibk
Created June 4, 2021 06:26
Show Gist options
  • Save tuansoibk/0afb92255f6c2493b9f86d060cd953e2 to your computer and use it in GitHub Desktop.
Save tuansoibk/0afb92255f6c2493b9f86d060cd953e2 to your computer and use it in GitHub Desktop.
Generate practices for custom keyboard layouts, to be used with Kiran Typing Tutor's course
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace TypingPractice
{
internal class Program
{
private static readonly char[][] LeftKeys = new[]
{
new[] {'1', '2', '3', '4', '5'},
new[] {'b', 'y', 'o', 'u', '\''},
new[] {'c', 'i', 'e', 'a', ','},
new[] {'g', 'x', 'j', 'k', '-'}
};
private static readonly char[][] RightKeys = new[]
{
new[] {'6', '7', '8', '9', '0'},
new[] {'"', 'l', 'd', 'w', 'v'},
new[] {'.', 'h', 't', 's', 'n'},
new[] {'=', 'r', 'm', 'f', 'p'}
};
private const int COL_COUNT = 5;
private const int HOME_ROW = 2;
private const int HOME_COL = 3;
private static List<string> Chapters;
public static void Main(string[] args)
{
Write(FingersPractice, @"C:\temp\keyboard\Engram\Practices\Basics.lesson");
Write(() => WordsPractice(3), @"C:\temp\keyboard\Engram\Practices\Words Of Three.lesson");
Write(() => WordsPractice(4), @"C:\temp\keyboard\Engram\Practices\Words Of Four.lesson");
Write(() => WordsPractice(5), @"C:\temp\keyboard\Engram\Practices\Words Of Five.lesson");
}
private static void Write(Action practiceFunc, string lessonPath)
{
Chapters = new List<string>();
practiceFunc();
Console.WriteLine(string.Join(Environment.NewLine, Chapters));
File.Create(lessonPath).Close();
File.AppendAllText(lessonPath, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + Environment.NewLine);
File.AppendAllText(lessonPath, "<chapters>" + Environment.NewLine);
File.AppendAllText(lessonPath, string.Join(Environment.NewLine, Chapters.Select(s => " " + s)) + Environment.NewLine);
File.AppendAllText(lessonPath, "</chapters>");
}
private static void WordsPractice(int charCount)
{
List<char> allChars = new List<char>();
allChars.AddRange(LeftKeys.SelectMany(row => row));
allChars.AddRange(RightKeys.SelectMany(row => row));
allChars = allChars.FindAll(char.IsLetter).ToList();
allChars.Add('q');
allChars.Add('z');
Random random = new Random();
for (int row = 0; row < 20; row++)
{
List<string> words = new List<string>();
for (int w = 0; w < 10; w++)
{
string word = "";
for (int c = 0; c < charCount; c++)
{
word += allChars[random.Next(0, allChars.Count)];
}
words.Add(word);
}
Print(string.Join(" ", words));
}
}
private static void FingersPractice()
{
// practice by row
SingeRow(HOME_ROW);
SingeRow(HOME_ROW - 1); // upper row
SingeRow(HOME_ROW - 2); // number row
SingeRow(HOME_ROW + 1); // lower row
// pratice by column
SingleColumn(HOME_COL); // index finger
SingleColumn(HOME_COL - 1); // middle finger
SingleColumn(HOME_COL - 2); // ring finger
SingleColumn(HOME_COL - 3); // pinky finger
SingleColumn(HOME_COL + 1); // index + 1 finger
}
private static void SingleColumn(int col)
{
string template = "112233445566 113355224466 123456 123456 135246 135246 214365 214365 246135 246135";
char leftKey1 = LeftKeys[HOME_ROW][col];
char leftKey2 = LeftKeys[HOME_ROW - 1][col];
char leftKey3 = LeftKeys[HOME_ROW + 1][col];
char rightKey1 = RightKeys[HOME_ROW][COL_COUNT - col - 1];
char rightKey2 = RightKeys[HOME_ROW - 1][COL_COUNT - col - 1];
char rightKey3 = RightKeys[HOME_ROW + 1][COL_COUNT - col - 1];
template = template
.Replace('1', leftKey1)
.Replace('2', leftKey2)
.Replace('3', leftKey3)
.Replace('4', rightKey1)
.Replace('5', rightKey2)
.Replace('6', rightKey3);
Print(template);
}
private static void SingeRow(int row)
{
SingleFinger(row, HOME_COL); // index finger
SingleFinger(row, HOME_COL - 1); // middle finger
SingleFinger(row, HOME_COL - 2); // ring finger
SingleFinger(row, HOME_COL - 3); // pinky finger
SingleFinger(row, HOME_COL + 1); // index finger + 1
TwoFingers(row, HOME_COL, HOME_COL - 1); // index + middle fingers
TwoFingers(row, HOME_COL - 2, HOME_COL - 3); // ring + pinky fingers
TwoFingers(row, HOME_COL, HOME_COL + 1); // index, index + 1 fingers
ThreeFingers(row, HOME_COL, HOME_COL - 1, HOME_COL - 2); // index, middle, ring fingers
ThreeFingers(row, HOME_COL - 1, HOME_COL - 2, HOME_COL - 3); // middle, ring, pinky fingers
ThreeFingers(row, HOME_COL, HOME_COL - 1, HOME_COL + 1); // index, middle, ring fingers
FourFingers(row); // index, middle, ring, pinky fingers
FiveFingers(row); // index, middle, ring, pinky fingers
}
private static void FiveFingers(int row)
{
string template = "11223344556677889900 1133557799 2244668800 1234567890 1234567890 1357924680 1357924680 2143658709 2143658709 2468013579 2468013579";
char leftKey1 = LeftKeys[row][HOME_COL];
char leftKey2 = LeftKeys[row][HOME_COL - 1];
char leftKey3 = LeftKeys[row][HOME_COL - 2];
char leftKey4 = LeftKeys[row][HOME_COL - 3];
char leftKey5 = LeftKeys[row][HOME_COL + 1];
char rightKey1 = RightKeys[row][COL_COUNT - HOME_COL - 1];
char rightKey2 = RightKeys[row][COL_COUNT - HOME_COL];
char rightKey3 = RightKeys[row][COL_COUNT - HOME_COL + 1];
char rightKey4 = RightKeys[row][COL_COUNT - HOME_COL + 2];
char rightKey5 = RightKeys[row][COL_COUNT - HOME_COL - 2];
template = template
.Replace('1', leftKey1)
.Replace('2', leftKey2)
.Replace('3', leftKey3)
.Replace('4', leftKey4)
.Replace('5', leftKey5)
.Replace('6', rightKey1)
.Replace('7', rightKey2)
.Replace('8', rightKey3)
.Replace('9', rightKey4)
.Replace('0', rightKey5);
Print(template);
}
private static void Print(string template)
{
Chapters.Add($"<chapter>{template}</chapter>");
}
private static void FourFingers(int row)
{
string template = "1122334455667788 11335577 22446688 12345678 12345678 13572468 13572468 21436587 21436587 24681357 24681357";
char leftKey1 = LeftKeys[row][HOME_COL];
char leftKey2 = LeftKeys[row][HOME_COL - 1];
char leftKey3 = LeftKeys[row][HOME_COL - 2];
char leftKey4 = LeftKeys[row][HOME_COL - 3];
char rightKey1 = RightKeys[row][COL_COUNT - HOME_COL - 1];
char rightKey2 = RightKeys[row][COL_COUNT - HOME_COL];
char rightKey3 = RightKeys[row][COL_COUNT - HOME_COL + 1];
char rightKey4 = RightKeys[row][COL_COUNT - HOME_COL + 2];
template = template
.Replace('1', leftKey1)
.Replace('2', leftKey2)
.Replace('3', leftKey3)
.Replace('4', leftKey4)
.Replace('5', rightKey1)
.Replace('6', rightKey2)
.Replace('7', rightKey3)
.Replace('8', rightKey4);
Print(template);
}
private static void ThreeFingers(int row, int col1, int col2, int col3)
{
string template = "112233445566 113355224466 123456 123456 135246 135246 214365 214365 246135 246135";
char leftKey1 = LeftKeys[row][col1];
char leftKey2 = LeftKeys[row][col2];
char leftKey3 = LeftKeys[row][col3];
char rightKey1 = RightKeys[row][COL_COUNT - col1 - 1];
char rightKey2 = RightKeys[row][COL_COUNT - col2 - 1];
char rightKey3 = RightKeys[row][COL_COUNT - col3 - 1];
template = template
.Replace('1', leftKey1)
.Replace('2', leftKey2)
.Replace('3', leftKey3)
.Replace('4', rightKey1)
.Replace('5', rightKey2)
.Replace('6', rightKey3);
Print(template);
}
private static void TwoFingers(int row, int col1, int col2)
{
string template = "11223344 11332244 12341234 13241324 21432143 24132413";
char leftKey1 = LeftKeys[row][col1];
char leftKey2 = LeftKeys[row][col2];
char rightKey1 = RightKeys[row][COL_COUNT - col1 - 1];
char rightKey2 = RightKeys[row][COL_COUNT - col2 - 1];
template = template
.Replace('1', leftKey1)
.Replace('2', leftKey2)
.Replace('3', rightKey1)
.Replace('4', rightKey2);
Print(template);
}
private static void SingleFinger(int row, int col)
{
string template = "1111 2222 1122 2211 1212 2121 12 12 21 21";
char leftKey = LeftKeys[row][col];
char rightKey = RightKeys[row][COL_COUNT - col - 1];
template = template
.Replace('1', leftKey)
.Replace('2', rightKey);
Print(template);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment