Algorithm for key buffer (cheat codes)

How are key buffers created in general? (for cheat codes or any general effect of that kind)

E.I.
When entering "cheat codes", the program listens for a series of key presses {e.g. pressing keyA, keyB, keyY, keyX, in a consecutive order}, and then activates an effect afterwards.
Last edited on
Not sure what you're going after here. Could you explain more?
I have an idea, not entirely sure if it will work and I have to go, I can make a class for this when I come home and test the idea further.

Setup for the struct (psuedo-code)
struct CheatCode
int progress (init as 0)
std::string code; (all lower OR uppercase)
function-pointer callback (see http://www.newty.de/fpt/index.html for function pointers)
put these in an array or a list.

Psuedo code for a possible function used by your keyboard callback function when a key is pressed, assuming you have one.
<convert to lower/upper case (the same as code)>
<iterate through cheat codes>
....<is it the the current->progress-th character>
..........<yes: increment current->progress by 1>
..........<no: set current->progress to 0>
....<is the current->progress on code->code.length)>
..........<yes: run callback function>
Topic archived. No new replies allowed.