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
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
################################################################################

/.vs
/OnScreenKeyboardScripter/.vs/OnScreenKeyboardScripter/v15
/OnScreenKeyboardScripter/OnScreenKeyboardScripter.Demo/bin/Debug
/OnScreenKeyboardScripter/OnScreenKeyboardScripter.Demo/obj
/OnScreenKeyboardScripter/OnScreenKeyboardScripter.Lib/bin/Debug
/OnScreenKeyboardScripter/OnScreenKeyboardScripter.Lib/obj
/OnScreenKeyboardScripter/OnScreenKeyboardScripter.Test/bin/Debug
/OnScreenKeyboardScripter/OnScreenKeyboardScripter.Test/obj
/OnScreenKeyboardScripter/packages
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?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>{DBA825CE-715D-4F3A-BD08-BDD8A3490CAA}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>OnScreenKeyboardScripter.Demo</RootNamespace>
<AssemblyName>OnScreenKeyboardScripter.Demo</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" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<Content Include="sample.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OnScreenKeyboardScripter.Lib\OnScreenKeyboardScripter.Lib.csproj">
<Project>{67c25f06-53a5-4536-8fe2-c8c92795b95a}</Project>
<Name>OnScreenKeyboardScripter.Lib</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
41 changes: 41 additions & 0 deletions OnScreenKeyboardScripter/OnScreenKeyboardScripter.Demo/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using lib = OnScreenKeyboardScripter.Lib;

namespace OnScreenKeyboardScripter.Demo
{
class Program
{
static void Main(string[] args)
{
if (System.IO.File.Exists("sample.txt"))
{
lib.IKeyboard keyboard = lib.Factory.GetKeyboard();
lib.IScripter scripter = lib.Factory.GetScripter();

System.IO.File.ReadAllLines("sample.txt")
.ToList()
.ForEach(line =>
{
string output = string.Empty;
try
{
output = scripter.GetPath(keyboard, line);
}
catch (Exception e)
{
output = string.Format("ERROR - unable to translate input:\n\t'{0}'\n{1}", line, e.Message);
}
Console.WriteLine(output);
});
}

Console.Write("Press key to exit");
Console.ReadKey();
}
}
}
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("OnScreenKeyboardScripter.Demo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OnScreenKeyboardScripter.Demo")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[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("dba825ce-715d-4f3a-bd08-bdd8a3490caa")]

// 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")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
IT Crowd
This has s*me b@d input
39 changes: 39 additions & 0 deletions OnScreenKeyboardScripter/OnScreenKeyboardScripter.Lib/Factory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OnScreenKeyboardScripter.Lib
{
/// <summary>
/// Single source for keyboards and scripters
/// </summary>
public sealed class Factory
{
static StructureMap.IContainer container = null;

/// <summary>
/// Gets the currently-registered <see cref="Keyboard"/> class.
/// </summary>
/// <returns><see cref="IKeyboard"/></returns>
static public IKeyboard GetKeyboard() { return container.GetInstance<IKeyboard>(); }
/// <summary>
/// Gets the currently-registered <see cref="Scripter"/> class.
/// </summary>
/// <returns><see cref="IScripter"/></returns>
static public IScripter GetScripter() { return container.GetInstance<IScripter>(); }

/// <summary>
/// Initializes the <see cref="Factory"/> class.
/// </summary>
static Factory()
{
container = new StructureMap.Container(cfg =>
{
cfg.For<IKeyboard>().Use<Keyboard>();
cfg.For<IScripter>().Use<Scripter>();
});
}
}
}
21 changes: 21 additions & 0 deletions OnScreenKeyboardScripter/OnScreenKeyboardScripter.Lib/IKeyboard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OnScreenKeyboardScripter.Lib
{
public enum MoveCursor
{
Up,
Down,
Left,
Right
}

public interface IKeyboard
{
List<MoveCursor> GetCursorPath(char fromKey, char toKey);
}
}
13 changes: 13 additions & 0 deletions OnScreenKeyboardScripter/OnScreenKeyboardScripter.Lib/IScripter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OnScreenKeyboardScripter.Lib
{
public interface IScripter
{
string GetPath(IKeyboard keyboard, string input);
}
}
94 changes: 94 additions & 0 deletions OnScreenKeyboardScripter/OnScreenKeyboardScripter.Lib/Keyboard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OnScreenKeyboardScripter.Lib
{
/// <summary>
/// Represents the on-screen keyboard layout and cursor-movement behavior.
/// </summary>
/// <seealso cref="OnScreenKeyboardScripter.Lib.IKeyboard" />
public class Keyboard : IKeyboard
{
public bool CursorWrapsHorizontally { get; set; } = true;
public bool CursorWrapsVertically { get; set; } = true;

const int rowWidth = 6;
const int rows = 6;

const string layout =
"ABCDEF" +
"GHIJKL" +
"MNOPQR" +
"STUVWX" +
"YZ0123" +
"456789";

/// <summary>
/// Gets the cursor path from current key-location on keyboard to next key-location
/// </summary>
/// <param name="fromKey">Starting key (cursor position) on keyboard</param>
/// <param name="toKey">Destination key (cursor position) on keyboard</param>
/// <returns></returns>
/// <exception cref="NotImplementedException">Unrecognized keyboard key</exception>
public List<MoveCursor> GetCursorPath(char fromKey, char toKey)
{
int idxFrom = layout.IndexOf(fromKey),
idxTo = layout.IndexOf(toKey);

if (idxFrom < 0 || idxTo < 0)
{
throw new NotImplementedException("Unrecognized keyboard key");
}

List<MoveCursor> cursorMovements = new List<MoveCursor>();

int fromY = (int)Math.Floor((double)idxFrom / (double)rowWidth),
fromX = idxFrom - (fromY * rowWidth),
toY = (int)Math.Floor((double)idxTo / (double)rowWidth),
toX = idxTo - (toY * rowWidth);

while (fromKey != toKey)
{
// go up instead of down if wrapping?
var upOverDown = (CursorWrapsVertically && ((fromY + rows - toY) < toY - fromY));
// go down instead of up if wrapping?
var downOverUp = (CursorWrapsVertically && (toY + rows - fromY) < fromY - toY);
// go left instead of right if wrapping
var leftOverRight = (CursorWrapsHorizontally && ((fromX + rowWidth - toX) < toX - fromX));
// go right instead of left if wrapping
var rightOverLeft = (CursorWrapsHorizontally && ((toX + rowWidth - fromX) < fromX - toX));

if ((toY < fromY && !downOverUp) || upOverDown)
{
cursorMovements.Add(MoveCursor.Up);
fromY = (fromY + rows - 1) % rows;
}
// go down?
else if (fromY < toY || downOverUp)
{
cursorMovements.Add(MoveCursor.Down);
fromY = (fromY + 1) % rows;
}
// go left? toX < fromX
else if ((fromX > toX && !rightOverLeft) || leftOverRight)
{
cursorMovements.Add(MoveCursor.Left);
fromX = (fromX + rowWidth - 1) % rowWidth;
}
// go right? toX > fromX
else if ((toX > fromX) || rightOverLeft)
{
cursorMovements.Add(MoveCursor.Right);
fromX = (fromX + 1) % rowWidth;
}

fromKey = layout[(fromY * rowWidth) + fromX];
}

return cursorMovements;
}
}
}
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>{67C25F06-53A5-4536-8FE2-C8C92795B95A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OnScreenKeyboardScripter.Lib</RootNamespace>
<AssemblyName>OnScreenKeyboardScripter.Lib</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<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' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="StructureMap, Version=4.6.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\StructureMap.4.6.1\lib\net45\StructureMap.dll</HintPath>
</Reference>
<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="Factory.cs" />
<Compile Include="Keyboard.cs" />
<Compile Include="Scripter.cs" />
<Compile Include="IKeyboard.cs" />
<Compile Include="IScripter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Loading