Yes, indeed, I must have mixed up several things.
The general idea is not mine; six years ago, I tried to implement this library:
It gave me a headache too, I never managed to get it working, too complicated for me.
Today, I simplified it as much as possible, and it works as I described above.
If it can help give you some ideas, here is how I did it.
OnKeyDown
Add to the snapshot all the pressed keys:
if (_mode == INSTANT_MODE && _IsInstantKey (key))
_snapshots.AddKey (key);
OnKeyUp
Memorize the pressed key combination and move to the next combination:
if (_mode == INSTANT_MODE && _IsInstantKey (key))
_snapshots.NextCombination ();
After a delay, execute the key sequences.
_debouncer.Debounce (_HandleSnapshots);
And here, the stupid class that does almost everything.
readonly SnapshotRecorder _snapshots = new ();
class SnapshotRecorder
{
byte _seq = 0;
readonly byte[] _count = new byte[5];
readonly Keys[][] _combinations = new Keys[5][];
public SnapshotRecorder ()
{
for (var i = 0 ; i < 5 ; i++ ) {
_combinations[i] = new Keys[5];
for (var j = 0 ; j < 5 ; j++ )
_combinations[i][j] = Keys.None;
}
}
/// Move to the next combination only if the current combination has pressed keys.
public void NextCombination ()
{
if (_count[_seq] > 0 && _seq < 4)
_seq++;
}
/// Add a pressed key to the current combination.
public void AddKey (Keys key)
{
if (_count[_seq] < 4) {
_combinations[_seq][_count[_seq]++] = key;
}
}
/// Reset all combinations.
public void Clear ()
{
for (var i = 0 ; i <= _seq ; i++ )
{
for (var j = 0 ; j <= _count[i] ; j++ )
_combinations[i][j] = Keys.None;
_count[i] = 0;
}
_seq = 0;
}
}
It might be a bit pretentious to imagine that this piece of code could be useful,
but compared to Globalmousekeyhook, the simplicity of this code for similar results surprised me.