How to Program N-key Rollover?

I am making a small macropad with the Arduino Micro. I am trying to program some sort of N-key Rollover where I can press up to 2 keys at once and have the arduino send a macro command with all 3 keys. I am NOT using the Keypad.h Library because it didn't work, and I am using external 10K pull-ups.

#define ROW1 6
#define ROW2 7

#define COL1 8
#define COL2 9

void setup()
{
  pinMode(ROW1, OUTPUT);
  pinMode(ROW2, OUTPUT);

  pinMode(COL1, INPUT);
  pinMode(COL2, INPUT);
  Serial.begin(9600);
}

void loop()
{
  digitalWrite(ROW1, LOW);
  digitalWrite(ROW2, HIGH);
  if (digitalRead(COL1) == LOW)
  {
    Serial.println("A");
  }
  if (digitalRead(COL2) == LOW)
  {
    Serial.println("B");
  }
   digitalWrite(ROW2, LOW);
  digitalWrite(ROW1, HIGH);
  if (digitalRead(COL1) == LOW)
  {
    Serial.println("C");
  }
  if (digitalRead(COL2) == LOW)
  {
    Serial.println("D");
  }
}

I will have more rows and columns in the final version.

It should work for multiple key presses easily.
Check this out:
I couldn't Press Two Buttons on Matrix Keypad with Arduino - Stack Overflow

I am not using the keypad library not because n-key rollover didn't work, but it didn't register any keypresses (I didn't have any pull-up resistors). I tried the keypad library with both pull-up and no pull-up and it didn't register any keypresses for either

Can you please show the wiring that you used when the library wouldn't work, along with that code?

The rows are pulled low and the column are input pull-ups

..."along with that code"...

Besides the fact that 2 doesn’t equal 3, that’s not what N-key rollover means.

Are you talking about “chords”, which seems like what you are saying, or do you mean you want multiple keystrokes to transmit the characters they represent as those keys go down, without needing that the keys come up before subsequent keystrokes are sent?

a7

I may be off here but with this layout do you need pullups? And with the directions of the diodes, shouldn't you energize the cols and read the rows instead of the other way round?

The keyboard circuit diagram is fine. See https://www.gammon.com.au/forum/?id=14175

Code is in original post. This is a scaled up version of the 2x2 code I posted

Naturally, we wonder what errors you introduced while "scaling it up", and what "didn't work" means.

the original error was that no keypresses were being registered. this was with a no external pull-up setup with the keypad.h library. I then tried without the keypad library and just tested one switch and I was getting junk output from the GPIO pin

Just one?

I suspect you are talking about "function keys", like SHIFT, ALT, CTRL. You do need N-key rollover support for that, but it's only half the battle. I also suspect that you are using the keypad library to detect key depressions only. That is not enough for function keys (your "macros"). Look at the keypad library to see whether it will detect key states, not just key state changes.

Are you talking about “chords”, which seems like what you are saying, or do you mean you want multiple keystrokes to transmit the characters they represent as those keys go down, without needing that the keys come up before subsequent keystrokes are sent?

Yes. I need that for multi key presses. Like pressing shift and 'A' at the same time

I am not using the keypad library at all because it did not work for this schematic, or my previous one. my previous one is basically the same thing without the pull-up resistors going to 5V

It didn't even detect a single keypress, let alone multiple

Fix the wiring problem.

Please post clear photos of your wiring.

That's why your keypad didn't work with the Keypad library. The Keypad library grounds the Column pins and turns on the pull-ups on the Row pins. Your keypad has pull-ups fighting the Column pins and diodes facing the wrong way.

You can remove the pull-up resistors and swap rows and columns to get the diodes going the right way. Then it should work.

See the Multikey example that came with the library. It will give you a list of up to 10 keys that are active (pressed, held, released, or recently released.)