This is a library that allows you to trigger cheat codes events in your game/application using .NET. The keystrokes handler is not included in this library because it really depends on the context where this library is used, most of the time, games use a third party to catch keystrokes not the one in the .NET Framework.
Introduction
I just didn't find any library doing this, or at least not with the criteria I wanted.
Background
The library is coded using C# and therefore it works on .NET environment like C#, VB.NET, F#.
In the Winform, you still can use "KeyDown
" event to catch keystrokes.
Using the Code
Just add a reference to the library in the release https://github.com/melharfi/CheatCodeLite/releases or using nuget:
Install-Package CheatCodeLite -Version 1.0.0
Once it's done, you can then use this code to start on a Winform:
using System.Collections.Generic;
using System.Windows.Forms;
using CheatCodeLite;
namespace winform_test
{
public partial class Form1 : Form
{
readonly CheatCodeLite.CheatCodeLite cch;
public Form1()
{
InitializeComponent();
int elapsedTime = 1000;
cch = new CheatCodeLite.CheatCodeLite(elapsedTime);
ChainePattern cp1 = new ChainePattern(new List<int>
{ (int)Keys.D, (int)Keys.O, (int)Keys.O, (int)Keys.M }, "DOOM");
cch.AddChainePattern(cp1);
ChainePattern cp2 = new ChainePattern(new List<int>
{ (int)Keys.H, (int)Keys.E, (int)Keys.L, (int)Keys.L, (int)Keys.O }, "HELLO");
cch.AddChainePattern(cp2);
cch.AddedPattern += CheatCodeHandler_AddedPattern;
this.KeyDown += Form1_KeyDown;
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
cch.AddKeystroke(e.KeyValue);
}
private void CheatCodeHandler_AddedPattern(object sender, PatternEventHandler e)
{
MessageBox.Show(e.ChainePattern.Alias +
" cheat code has been triggered", ":-)", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
}
Pay attention that the value passed to the CheatCodeLite.CheatCodeLite(int keystrokesInterval)
is the time allowed to keep chained cheat code, if this time is overwhelmed, then the cheat code in progress is reset.
To disable this timer, just put a very long value like 100000000. :)
Pay attention to some scenarios that will raise some error. When a cheat code is registered like "HELLO
" in the first hand, and another cheat code is registered like "HELL
", in that case, the second cheat code will hide the first one because cheat code will be reset as soon as it trigger the "HELL
" event, so to avoid that, an exception will be thrown to prevent and warn you about that.
Same scenario when the reverse happens, when you first add a cheat code like "HELL
" and you just add another one like "HELLO
", then the second one will be hidden by the first one.
Same thing when a duplication is found.
Points of Interest
Simple to use, rare library shared to do that "at least I didn't find some".
History
- 23rd October, 2020: First release