IBM Numeric PS/2 Keypad (Black, 17 keys) Model No. KB-9880 FRU: 19K2058 P/N: 07G0032
Keypad Interface
I purchased an IBM 07G0032 keypad on eBay for $6 thinking it would plug into the keyboard port and probably act like the right end of a regular PS/2 keyboard. However, this keypad was intended for a Thinkpad laptop computer that only had an external mouse connector. The pinout of the PS/2 connector was different and even the keycodes and the way the key-up code worked was not the same. However, it actually makes the interface to the NXT easier.
The key-down codes are shown below, and the key-up code is just this code plus 128. Unlike the PS/2 keyboard which sends F0hex and repeats the key-down code. The keypad also does not resend the key-down code repeatedly if you hold a key down for a long time. Both of these features makes the NXT software much easier. Other than the PS/2 connector pinout, the hardware is the same as my keyboard interface.
The NXT-G program below calls the KeyNum MyBlock twice to create a two digit number that is passed to my custom block for the TDA8444. It only works correctly if you hit two consecutive 0 to 9 number keys. The KeyNum MyBlock is also shown below. It just loops untill it sees that a new keycode has been received and that the value is for a key-down code. Then it looks up the numerical value of the key from a file called keynum.txt. Keys other than the numbers have values 10 and greater. Ideally these would be used to signify negative, delete, enter etc.
Here is a little video of the keypad interface in action.