Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions SoftWritersOSK.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2015
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftWritersOSK", "SoftWritersOSK\SoftWritersOSK.csproj", "{F8702A6F-2274-4E82-ADAD-DC00AE710210}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F8702A6F-2274-4E82-ADAD-DC00AE710210}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F8702A6F-2274-4E82-ADAD-DC00AE710210}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F8702A6F-2274-4E82-ADAD-DC00AE710210}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F8702A6F-2274-4E82-ADAD-DC00AE710210}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3DCC65CA-DF7B-4527-940E-998939B0AB54}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions SoftWritersOSK/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
18 changes: 18 additions & 0 deletions SoftWritersOSK/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoftWritersOSK
{
class Program
{
static void Main(string[] args)
{
string file = "..\\..\\input.txt";
Traverse.TraverseFile(file);
Console.ReadLine();
}
}
}
36 changes: 36 additions & 0 deletions SoftWritersOSK/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SoftWritersOSK")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SoftWritersOSK")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f8702a6f-2274-4e82-adad-dc00ae710210")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
28 changes: 28 additions & 0 deletions SoftWritersOSK/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# On Screen Keyboard
---
The requirement for this program is to script the path for the cursor of an on screen keyboard. The Traverse class in this program provides the following methods to fulfill this requirement;

1. ConvertASCII()
* ConvertASCII() takes a char as input, converts it to it's ASCII code, and subtracts the offset of 65 for the characters 'a' through 'z' (case insensitive) so that 'a' would return a value of 0, 'b' of 1, etc. The characters '1' through '9' return the values of 26 through 34, and the character '0' returns the value of 35. These values represent the relative position of each character within the "keyboard".

2. TraverseChar()
* TraverseChar() takes two chars as inputs; char a and char b. Char a represents the cursor's current position, or the previously navigated character. Char b represents the char to be navigated to. TraverseChar() calculates the direction of travel by subtracting the cursor location from the target location. If the difference is less than or equal to negative six, then the direction of travel is up. Greater than or equal to positive 6, the direction of travel is down. Between 0 and negative six, the direction of travel is left. Between 0 and positive six, the direction of travel is right. The floors of a/6 and b/6 are also calculated and compared so that left and right operations never attemt to jump "lines", but instead output the proper up and to the right, or down and to the left directions.

3. TraverseString()
* TraverseString() takes a string as input and calls TraverseChar() for each character in that string. The cursor path for the entire input string is returned.

4. TraverseFile()
* TraverseFile() takes a file path string as input and calls TraverseString() for each line in the file, printing out the cursor path for each line as it goes.

# Limitations
---
This program assumes that the on screen keyboard is laid out as follows;
```
ABCDEF
GHIJKL
MNOPQR
STUVWX
YZ1234
567890
```
The characters of the keyboard are calculated mathematically and not stored in any data structure. Changing the layout of the keyboard requires adjusting the math in ConvertASCII() and TraverseChar().
57 changes: 57 additions & 0 deletions SoftWritersOSK/SoftWritersOSK.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F8702A6F-2274-4E82-ADAD-DC00AE710210}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>SoftWritersOSK</RootNamespace>
<AssemblyName>SoftWritersOSK</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Traverse.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="README.md" />
</ItemGroup>
<ItemGroup>
<Content Include="input.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
113 changes: 113 additions & 0 deletions SoftWritersOSK/Traverse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoftWritersOSK
{
/*
The Traverse class provides methods for outputting navigation
directions between characters in a string
*/
static class Traverse
{
/*
ConvertASCII returns the values 0-25 for the characters A-Z,
the values 26-34 for characters 1-9,
and the value of 35 for the character 0.
These integers are arbitrary "indices" that allow for the
calculation of cardinal directions
*/
public static int ConvertASCII(char a)
{
int aa = (int)a;
if (aa <= 57 && aa > 48)
aa += 42;
if (aa == 48)
aa += 52;

return aa - 65;
}

//TraverseChar provides output for the path between char a and char b
public static string TraverseChar(char a, char b)
{
int aa = ConvertASCII(a);
int bb = ConvertASCII(b);
string path = "";
//Compares the positions of a and b. If b is on the line above a, it moves the "cursor" up
while ((bb - aa) <= -6 || (Math.Floor((decimal)aa / 6) > Math.Floor((decimal)bb / 6)))
{
path += "U,";
aa -= 6;
}
//Compares the positions of a and b. If b is on the line below a, it moves the "cursor" down
while ((bb - aa) >= 6 || (Math.Floor((decimal)aa / 6) < Math.Floor((decimal)bb / 6)))
{
path += "D,";
aa += 6;
}
//Compares the positions of a and b. If b is to the left of a, it moves the "cursor" left
while ((bb - aa) <= -1)
{
path += "L,";
aa -= 1;
}
//Compares the positions of a and b. If b is to the right of a, it moves the "cursor" right
while ((bb - aa) >= 1)
{
path += "R,";
aa += 1;
}
//Checks if the "cursor" is located at the target character, and appends the select character if it is.
if (bb == aa)
path += "#";

return path;
}
/*
TraverseString calls TraverseChar for each character in the input string
and returns the pathing string for the entire input string
*/
public static string TraverseString(string word)
{
char current = (char)0;
char next = (char)0;
char[] wordArray = word.ToUpper().ToCharArray();
string path = "";
//Cycles through every character in the input string
for (int i = 0; i < wordArray.Length; i++)
{
next = wordArray[i];
if ((int)current == 0)
current = 'A';
if (wordArray[i] == ' ')
{
path += "S";
}
else
{
path += TraverseChar(current, next);
current = next;
}
if (i != wordArray.Length - 1)
path += ',';
}

return path;
}

//TraverseFile takes a file path as input and outputs the cursor path for each line of the input file.
public static void TraverseFile(string file)
{
foreach (string line in System.IO.File.ReadLines(file))
{
System.Console.WriteLine(Traverse.TraverseString(line));
}
}
}
}



Binary file added SoftWritersOSK/bin/Debug/SoftWritersOSK.exe
Binary file not shown.
6 changes: 6 additions & 0 deletions SoftWritersOSK/bin/Debug/SoftWritersOSK.exe.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
Binary file added SoftWritersOSK/bin/Debug/SoftWritersOSK.pdb
Binary file not shown.
2 changes: 2 additions & 0 deletions SoftWritersOSK/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
it crowd
Hello World
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
60366f36ef93ce4e81e211609bb7fa28fa159d28
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
C:\Users\Sean\Source\repos\SoftWritersOSK\SoftWritersOSK\obj\Debug\SoftWritersOSK.csprojResolveAssemblyReference.cache
C:\Users\Sean\Source\repos\SoftWritersOSK\SoftWritersOSK\obj\Debug\SoftWritersOSK.csproj.CoreCompileInputs.cache
C:\Users\Sean\Source\repos\SoftWritersOSK\SoftWritersOSK\bin\Debug\SoftWritersOSK.exe.config
C:\Users\Sean\Source\repos\SoftWritersOSK\SoftWritersOSK\bin\Debug\SoftWritersOSK.exe
C:\Users\Sean\Source\repos\SoftWritersOSK\SoftWritersOSK\bin\Debug\SoftWritersOSK.pdb
C:\Users\Sean\Source\repos\SoftWritersOSK\SoftWritersOSK\obj\Debug\SoftWritersOSK.exe
C:\Users\Sean\Source\repos\SoftWritersOSK\SoftWritersOSK\obj\Debug\SoftWritersOSK.pdb
Binary file not shown.
Binary file added SoftWritersOSK/obj/Debug/SoftWritersOSK.exe
Binary file not shown.
Binary file added SoftWritersOSK/obj/Debug/SoftWritersOSK.pdb
Binary file not shown.