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!");
}
});
The Cheet.Wpf.Demo
project in this repository demos all of the above sequences.
Install-Package Cheet.Core
Install-Package Cheet.Wpf
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.
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.
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.
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.
Disable a previously-mapped sequence.
sequence
(String)The same string you used to map the callback when using
cheet.Map(seq, ...)
.
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, ...)
.
NOTE: Key names are case-sensitive
left
|L
|←
up
|U
|↑
right
|R
|→
down
|D
|↓
0
-9
(main number keys)a
-z
backspace
tab
enter
|return
shift
|⇧
control
|ctrl
|⌃
alt
|option
|⌥
command
|⌘
pause
capslock
esc
space
pageup
pagedown
end
home
insert
delete
equal
|=
comma
|,
minus
|-
period
|.
kp_0
-kp_9
kp_multiply
kp_plus
kp_minus
kp_decimal
kp_divide
f1
-f12
MIT
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!