Cheet.NET

easy easter eggs (konami code, etc) for .NET

View the Project on GitHub jamiehumphries/Cheet.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 the GitHub repository demos all of the above sequences.

Install

NuGet

Core project:

Install-Package Cheet.Core

WPF version:

Install-Package Cheet.Wpf

API

cheet.Map(sequence, done | callbacks { done, next, fail })

Map a sequence of keypresses to a callback. This can be called multiple times.

sequence (String)

A string representation of a sequence of key names.

Each keyname must be separated by a single space.

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.

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.

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.

cheet.Done(callback)

Set a global callback that executes whenever any mapped sequence is completed successfully.

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.

cheet.Next(callback)

Set a global callback that executes whenever any mapped sequence progresses.

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.

cheet.Fail(callback)

Set a global callback that executes whenever any in-progress sequence is broken.

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.

cheet.Disable(sequence)

Disable a previously-mapped sequence.

sequence (String)

The same string you used to map the callback when using cheet.Map(seq, ...).

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.

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

Alphanumeric

Misc

Keypad

Function keys

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!