Cheet.NET
Easy easter eggs (Konami code, etc) for .NET
Install / Use
/learn @jamiehumphries/Cheet.NETREADME
Cheet.NET
easy easter eggs in .NET
This is a .NET port of the excellent cheet.js by Louis Acresti (namuol). I would recommend checking out that project if you need easter egg functionality in browser!
// Initialization
var cheet = new Cheet();
myUIElement.PreviewKeyDown += cheet.OnKeyDown;
cheet.Map("↑ ↑ ↓ ↓ ← → ← → b a", () => { Debug.WriteLine("Voilà!"); } );
cheet.Map("i d d q d", () => {
Debug.WriteLine("god mode enabled");
});
cheet.Map("o n e a t a t i m e", new CheetCallbacks {
Next = (str, key, num, seq) => {
Debug.WriteLine("key pressed: " + key);
Debug.WriteLine("progress: " + (double)num / seq.Length);
Debug.WriteLine("seq: " + String.Join(" ", seq));
},
Fail = (str, seq) => {
Debug.WriteLine("sequence failed");
},
Done = (str, seq) => {
Debug.WriteLine("+30 lives ;)");
}
});
cheet.Map("o n c e", () => {
Debug.WriteLine("This will only fire once.");
cheet.Disable("o n c e");
});
dynamic sequences = new {
Cross = "up down left right",
Circle = "left up right down"
};
cheet.Map(sequences.Cross);
cheet.Map(sequences.Circle);
cheet.Done((str, seq) => {
if (str == sequences.Cross) {
Debug.WriteLine("cross!");
} else if (str == sequences.Circle) {
Debug.WriteLine("circle!");
}
});
Demo
The Cheet.Wpf.Demo project in this repository demos all of the above sequences.
Install
NuGet
Install-Package Cheet.Core
Install-Package Cheet.Wpf
API
<a name='api_cheet'></a>
cheet.Map(sequence, done | callbacks { done, next, fail })
Map a sequence of keypresses to a callback. This can be called multiple times.
<a name='api_cheet_sequence'></a>
sequence(String)A string representation of a sequence of key names.
Each keyname must be separated by a single space.
<a name='api_cheet_done'></a>
done(str, seq)(callback)A callback to execute each time the sequence is correctly pressed.
Arguments:
str- The string representation of the sequence that completed.seq- An array of keys representing the sequence that completed.<a name='api_cheet_fail'></a>
fail(str, seq)(callback)A callback to execute each time a sequence's progress is broken.
Arguments:
str- The string representation of the sequence that failed.seq- An array of keys representing the sequence that was pressed.<a name='api_cheet_next'></a>
next(str, key, num, seq)(callback)A callback to execute each time a correct key in the sequence is pressed in order.
Arguments:
str- The string representation of the sequence that is in progress.key- The name of the key that was just pressed.num- A number representing the current progress of the sequence. (starts at 0)seq- An array of keys representing the sequence that is in progress.
<a name='api_done'></a>
cheet.Done(callback)
Set a global callback that executes whenever any mapped sequence is completed successfully.
<a name='api_done_callback'></a>
callback(str, seq)(callback)A callback to execute each time any sequence is correctly pressed.
Arguments:
str- The string representation of the sequence that completed.seq- An array of keys representing the sequence that completed.
<a name='api_next'></a>
cheet.Next(callback)
Set a global callback that executes whenever any mapped sequence progresses.
<a name='api_next_callback'></a>
callback(str, key, num, seq)(callback)A callback to execute each time a correct key in any sequence is pressed in order.
Arguments:
str- The string representation of the sequence that is in progress.key- The name of the key that was just pressed.num- A number representing the current progress of the sequence. (starts at 0)seq- An array of keys representing the sequence that is in progress.
<a name='api_fail'></a>
cheet.Fail(callback)
Set a global callback that executes whenever any in-progress sequence is broken.
<a name='api_fail_callback'></a>
callback(str, seq)(callback)A callback to execute each time any sequence's progress is broken.
Arguments:
str- The string representation of the sequence that failed.seq- An array of keys representing the sequence that was pressed.
<a name='api_disable'></a>
cheet.Disable(sequence)
Disable a previously-mapped sequence.
<a name='api_disable_sequence'></a>
sequence(String)The same string you used to map the callback when using
cheet.Map(seq, ...).
<a name='api_reset'></a>
cheet.Reset(sequence)
Resets a sequence that may or may not be in progress.
This will not cause Fail callbacks to fire, but will effectively
cancel the sequence.
<a name='api_reset_sequence'></a>
sequence(String)The same string you used to map the callback when using
cheet.Map(seq, ...).
Available Key Names
NOTE: Key names are case-sensitive
Directionals
left|L|←up|U|↑right|R|→down|D|↓
Alphanumeric
0-9(main number keys)a-z
Misc
backspacetabenter|returnshift|⇧control|ctrl|⌃alt|option|⌥command|⌘pausecapslockescspacepageuppagedownendhomeinsertdeleteequal|=comma|,minus|-period|.
Keypad
kp_0-kp_9kp_multiplykp_pluskp_minuskp_decimalkp_divide
Function keys
f1-f12
License
MIT
Acknowledgements
This whole project was inspired and based on cheet.js by Louis Acresti (namuol). The API and all of this documentation is lifted from that project!
