There are $n$ empty positions in which we can put our available digits
$$\underbrace{\text{_ _ _ _ ... _ _}}_{n\text{ positions}}$$
each successive position may take on any of the $m$ possible digits hence there are
$$\text{possible key codes}=m^n\qquad\blacksquare$$
However, this counts keycodes length $n$ that use at most $m$ digits.
In order to count those keycodes that use at least one of each digit form sets $A_k$ of keycodes that use only the $m$ known digits but don't use the digit $k$ (which is amongst those $m$ digits). Then there are $\binom{m}{1}$ sets $A_k$ with cardinality:
$$|A_k|=(m-1)^n$$
because there are $(m-1)^n$ keycodes using the remaining $m-1$ digits.
Similarly there are $\binom{m}{2}$ set intersections (keycodes that don't use digits $k$ and $l$) which have cardinality:
$$|A_k\cap A_l|= (m-2)^n$$
this time there are $m-2$ digits for each position of the the keycode. higher order intersections look similar, for the $\binom{m}{3}$ 3-intersections we have:
$$|A_k\cap A_l\cap A_p|=(m-3)^n\\\vdots$$
Using the principle of inclusion-exclusion the number of valid keycodes that belong to none of the $A_k$ is given by:
$$\boxed{\text{valid keycodes}=m^n-\binom{m}{1}(m-1)^n+\binom{m}{2}(m-2)^n-\binom{m}{3}(m-3)^n+\ldots +(-1)^{m-1}\binom{m}{m-1}1^n\qquad\blacksquare}$$
This is related to the Stirling Numbers of the second kind $S(n,m)$ via
$$\text{valid keycodes}=m!S(n,m)$$