Keypad library EventListener

In the eventListener invocation code:

void Keypad::transitionTo(byte n, KeyState nextState) {
	key[n].kstate = nextState;
	key[n].stateChanged = true;

	if (keypadEventListener!=NULL)

Why is allways key[0] passed and not the key generating the event ?

I find more usefull


or even beter:


so you can ask for:

void keypadEvent(KeypadEvent key){
  switch (key.kstate){
    case PRESSED:


Why is allways key[0] passed and not the key generating the event ?

Well, probably because somebody made a mistake when they refactored the library. :wink: The original library only allowed single key presses and I later modified it to allow multiple key presses at the same time.

I'm off to bed right now so I will take a look at your suggested changes tomorrow.

OK, so here's the problem. keypadEventListener, a callback routine, was written for the keypad library when only a single key was allowed. If you pressed more than one key at a time then everything after the first key was ignored.

When I rewrote the library to support multiple keypresses I created a Key class that lets each key store its own character, code, changed status, and state. So now if you use getKeys() in your loop instead of getKey() then you will have a list that stores up to 10 active keys.

I mainly kept keypadEventListener for backwards compatibility with sketches that were written before the multi-key update. If I were to change




then any sketches using keypad events and the single-key getKey() function would be broken. But I still wanted the callback to occur on every state change for every key. So if you use the multi-key version, getKeys(), you can still use keypad events but you'll just have to ignore the key character.

Another option is to create a different addEventListener function that works with multiple key presses.