Some truths about keyboard hacks
I know this is an old thread, but i just had to reply to a few things i read with some facts.
first, somone commented that new keyboards do not have ghosting and diodes are an 'urban legend'.
well being an engineer, I can say that it is an electrical imposibility to avoid ghosting and masking in a keyboard matrix (or any matrix) unless you use diodes. the use of diodes in a matrix to prevent ghosting and masking is common practice. FYI, the typical doide used is a 1N4148 which are also VERY cheap.
Around 1989 keyboard manufacturers changed to controller code to ignore keypresses combinations that would cause a ghost charaters.
This does change things when hacking a keyboard. Some keyboards will block listening for a keypress (switch closing) that would otherwise cause a mask or ghost condition until the key combination being pressed allows for that key to be used without a ghost condition. on the other hand, if they do not check for this condition the diode works very well. ghosting and masking is still there without diodes. but with diodes it allows for all keys to be registered without masking or ghosting.
so the limitations of how far you can go (number of sumultaniously usable keys) with your keyboard hack is a mater of the keyboard controllers coding.
Thje bottom line on diode use. if you have an old keyboard where you can actualy press keys and create a ghost character, then use diodes and you can extend the number of simultanious inputs you can get without ghosting (up to the number of keys you have on the keyboard).
if your keyboard shows no ghosting, but keys are masked when hitting multiple keys, then the controlers code is stoping the possibiltiy of a ghost situation. if you can avoid all of those combinations then you dont need diodes, but if you have some you want to use for non player keys (i.e coin, player1 etc..) you should still use them to prevent a possible masking situation.
Anther comment made, 'keyboard hacks are not sutable for more than 3 buttons.'
Again not true. Lets take a closer look. A typical keyboard has over 100 buttons, each can be isolated and used sumultaniously as long as there is a diode inline with each switch. (less with newer keyboards see above)
As far as speed goes, keyboards are fast.
how fast is fast....
All key in a keyboard are checked every 10 milliseconds. Any device you use (keyboard interface or not), has to debounce the switch closing for around 20 milliseconds before it is sent to your computer, this makes a keyboard as fast as any other device since they all will wait to debounce the switch closing before considering a switch closed.
Tech Note: 20ms works nicely into 2 pollings (key checks) of the key in a keyboard interface. After the key is debounced it is placed in the keyboards output buffer to go to the pc (yes keyboards have output buffers built in, not that you can hit keys/buttons fast enough for it to make a diffrence)
Each key in the matrix handle around 50 transitions a second (a transition is either closing or opening a switch) most keyboards can handle over with over 100 inputs giving the ability to handle 5000 key (switch) transitions in a second.
Tech Note: (how i got the 5000 transitions number) figure 20ms to debounce a key transition. 1000ms/ 20ms = 50 key transitions maximum per second times 100 keys = 5000 transitions.
One last note for those of you who still think keyboard interfaces might be slow, I would like to meet the person who can press a single button 25 times a second!!! (25 presses+25 depresses=50 transitions per key or switch)
There are folks out there using 49 way joysticks on a keyboard interface.
now thats interfacing!
There are pleanty of legitimate reasons not do do a keyboard hack. It takes time to map out the keys, check to see what can and cannot be used together as not many keyboards are the same.
I would agree that keyboard hacking is not for the faint of heart. but you can't beet the price and it is alot of fun.
I hope this helps with any mis information.
PLEASE PLEASE PLESE, if you wish to add more facts or correct any facts I have here please do. It would be great to see more information based on facts not guess work on this very inexpensive and versital type of interfacing.
Personaly i would love to hear of others matrix tricks, I am hoping i can get the time to post some of mine.
If I have time, i'll do a full writeup on keyboard masking, ghosting, debouncing explination, performance, diode use, and some very neet tricks you can pull with a matrix you cant otherwise do with a non-matrix input device.
If you want to try using diodes, the diode i use is a 1N4148
diodes only let the keyboard polling singnal go one way.
so, if you put it in the wrong way, the switch will not function. if that happens just turn the diode around. (they are marked with a band on one side)
unless you are doing somthing fancy, you will need to put the diodes on each of you switches connected to the keyboard interface.
Antoher peice of advice is to not let the diode get very hot if you solder to it. otherwise it might be damaged, (if you suspect you damaged one, just use a multi-meters ohm meter to check it. one way should give a very low resistance reading, and swaping the leads the other way it sould give a high resistance reading)
Disclaimer: as always use this information at your own risk.
Happy Interfacing
Innkeeper