#1 is a perfect sentence. By placing the adjective phrase, "taking the keys out of his pocket", directly next to the noun that it modifies ("he"), it achieves maximum clarity.
#2 is a bad sentence. The adjective phrase "opening the door" is placed next to a noun, "pocket" that it does not modify. The pocket is not opening the door. In addition to that small problem, there is also a huge problem. The really bad mistake in #2 is that it attempts to use "opening" as if it were a verb. "Opening" is an adjective, not a verb. As a present participle, "opening" can have an object ("door") but it cannot have a subject. It is not permissible to say "He opening the door". A verb is needed ("opened"). You also need either a conjunction or a comma:
"He took the keys out of his pocket, then opened the door."
"He took the keys out of his pocket and then opened the door."