Here is my answer for a code of length $n$ using $k$ different digits which may be repeated arbitrarily often. Each digits must appear at least once. (otherwise it won't be worn out.)
This uses the corresponding sequence “A019538” which Barry Cipra mentioned.
Now, referencing OEIS is all nice and all, but if you aren't a mathematician chances are that page is quite confusing. It has a bunch of comments all seemingly pointing at a different meaning. None of those meanings in the one we actually have. (The “Number of $k$ dimensional 'faces' of the $n$ dimensional permutohedron” doesn't look like like numbers on a keypad to me at all... And WTF even is a permutohedron?)
Here is a formulation we can turn into a keypad: “Number of surjections (onto functions) from an $n$-element set to a $k$-element set.”
What is a “surjection from an $n$-element set to a $k$-element set”? It's an assignment which assigns one out of $k$ numbers each of $n$ places. Numbers can occur arbitrarily often and the “surjection” tells us each of the $k$ elements must be picked at least once. Great! That is exactly what we are looking for. Each position $n$ positions of the code is assigned one out of $k$ worn out keys and each key is picked at least once.
We are on the right OEIS page, let's get a formula. (There are many)
$$T(n, k) = k*\left(T(n-1, k-1)+T(n-1, k)\right) \text{ with } T(0, 0) = 1$$
That is not exactly a “plug in your numbers and get a result” formula – but with a small table getting a value is easy enough. And this formula happens to be easy to explain.
First of, why is $T(0,0) = 1$? This counts the ways you can enter a code of length $0$ using no digits. It sounds slightly insane if you see this the first time, but there is exactly one way to do that: Stand there and don't do anything.
Now where does $T(n, k) = k*\left(T(n-1, k-1)+T(n-1, k)\right)$ come from? For the first place, we have $k$ different possibilities. What about the other $n-1$ places which follow? We split this into two cases:
- The first digit is never used again. Then there are $T(n-1, k-1)$ ways to fill out the last $n-1$ digits with $k-1$ numbers.
- The first digit is used again. There there are $T(n-1, k)$ ways to fill out the last $n-1$ digits with $k$ numbers.
In sum, that gives us $T(n-1, k-1)+T(n-1, k)$ ways to fill out the last $n-1$ places times $k$ ways to fill out the first digit.
Here are some values which were also kindly supplied by OEIS:
n\k 1 2 3 4 5 6 7 8 9
1: 1
2: 1 2
3: 1 6 6
4: 1 14 36 24
5: 1 30 150 240 120
6: 1 62 540 1560 1800 720
7: 1 126 1806 8400 16800 15120 5040
8: 1 254 5796 40824 126000 191520 141120 40320
9: 1 510 18150 186480 834120 1905120 2328480 1451520 362880
In conclusion, if you use a lenght from three to six, double a single digit. For seven, eight and nine you should use two less and if you are using even longer codes, ask on stackoverflow for coding help.
I hope that helps.