I want to emulate keyboard presses in an old C64 microcomputer using an Arduino.

The keyboard connection is a non-standard 20-pin port (i.e. the Arduino keyboard libraries won't be useful) which, as I understand, works as a simple matrix of switches.

Since my Arduino Mega has more than 20 general purpose I/O ports, I understand I can approach the problem by simply mapping these 20 keyboard pins to individual "digital" Arduino ports, and then programming around it, right?

Or is this too naive and I'm missing something here?

I'm new to Arduino, so any comments highly appreciated. Thank you!


1 Answer 1


Emulating a keyboard matrix is actually harder than you would at first think. It's not just a case of setting certain combinations of pins as HIGH or LOW - you need to actively monitor one side of the matrix as it sweeps across each row and control the other side depending on the buttons that are pressed or not pressed on the current row. And all that has to be done fast enough that the C64 doesn't see buttons constantly bouncing up and down.

Further, you really need all your outputs to be open drain so as not to interfere with each other or the rest of the system (depending on just how the C64 system works), and Arduinos can't do open drain natively - instead you have to emulate it by switching between INPUT and OUTPUT + LOW which adds extra latency.

If you only want access to a few of the buttons a better arrangement would be to add a small N-channel (logic level) MOSFET or an NPN BJT between the two sides of the matrix for whichever button(s) you want to control (check the schematics for which pins and which way round to connect it). Activating the transistor would then be the same as pushing the button down. It can even be in parallel to the existing button so as to not break the keyboard.

  • Thank you Majenko! I'll reconsider the project given your valuable input -- not giving up yet, but more reading up to do... And I want to emulate the entire keyboard (including possible key combinations, e.g. Ctrl + something).
    – dust
    Commented Nov 28, 2016 at 12:09
  • The main concern you have with emulating a matrix is "what is the time between a row being activated and the column being read?" - If there is a good sized delay between the two then you could be in luck and it will be easy. If it's almost instantaneous then you could well have problems. You have to make sure that all the outputs are set right before that read is done. You may end up having to do it with a different system, such as a CPLD, in order to get the speed you need.
    – Majenko
    Commented Nov 28, 2016 at 12:12
  • I would go for two 4051 connected by common line and multiplexed lines to rows / cols (as Commodore keyboard is 8x8 matrix)
    – KIIV
    Commented Nov 28, 2016 at 13:23
  • I know this is out there but how about using the Arduino to drive relays to re-enact the key being pressed. Just a crazy idea.
    – sa_leinad
    Commented Nov 28, 2016 at 16:54
  • KIIV, as far as I understand 4051 demultiplexing, in this arrangement I would not be able to simulate key combinations. It seems 4051 enables you to select 1 output at a given time. So with two 4051s (one for row, one for column) I would be able to simulate 'F3' and 'Ctrl' at a time, but not 'Ctrl + F3' simultaneously.
    – dust
    Commented Nov 28, 2016 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.