Java 149 160 chars
The obligatory: Because... you know... Java!
Having fun with Java in under 150 161 chars:
int d(int f,int t){if(f==t)return 0;if(Math.min(f,t)==0){int m=Math.max(f,t);return Math.min(d(1,m),d(2,m))+1;}return Math.abs(--t%3- --f%3)+Math.abs(t/3-f/3);}
Ungolfed into a class:
public class Q80357 {
static int distance(int from, int to) {
if (from == to)
return 0;
if (Math.min(from, to) == 0) {
int max = Math.max(from, to);
return Math.min(distance(1, max), distance(2, max)) + 1;
}
return Math.abs(--to % 3 - --from % 3) + Math.abs(to / 3 - from / 3);
}
}
How it works
First it catches the standard case where we don't have to move anywhere.
Now we can assume that both integers differ, thus only the smaller one can be 0. If this is the case we calculate the distance from key 1 and 2 to the other key. We will use the one with the shorter distance and add one step to get from 1 or 2 to 0.
If we don't want to go to/from zero we only have to move in the 3x3 grid. We can determine the column and row of the key by using mod or div respectively. Then we calculate the column and row distance and add them. This is the distance we need to get from one key to another.
I hope the explanation could be understood, feel free to golf :)
Updates
Had to change it into an actual function as it uses recursion which isn't possible with lambdas :,(