No, your condition is not enough.
For example, take two distinct finite nonabelian simple groups $G$ and $H$ such that neither one is a subgroup of the other (such pairs exist; the condition is in fact stronger than it needs to be, as witnessed by the theorem quoted in the end; you just need $G$ and $H$ to be distinct). By the odd-order theorem, both $|G|$ and $|H|$ are even, so $\gcd(|G|,|H|)\neq 1$.
Let $\iota_G$ and $\iota_H$ be the inclusions into the product, and $\pi_G$, $\pi_H$ the projections. Let $f\colon G\times H \to G\times H$ be an automorphism.
Then $\pi_H\circ f\circ\iota_G \colon G\to H$ is a homomorphism. Since $H$ does not contain a subgroup isomorphic to $G$ and $G$ is simple, the composition must be the trivial map. Therefore, $f(g,e)\in G\times\{e\}$ for all $g\in G$. Symmetrically, by looking at $\pi_G\circ f\circ \iota_H$, we conclude that $f(e,h)\in \{e\}\times H$ for all $h\in H$. Therefore, $f|_{G\times\{e\}} = \alpha\in \mathrm{Aut}(G)$, and $f|_{\{e\}\times H} = \beta\in \mathrm{Aut}(H)$. So every automorphism of $G\times H$ corresponds to an element of $\mathrm{Aut}(G)\times\mathrm{Aut}(H)$, and of course the restrictions completely determine $f$.
You may want to consider:
Bidwell, J.N.S., Curran, M.J., and McCaughan, D. Automorphisms of direct products of finite groups, Arch. Math. (Basel) 86 (2006) no. 6, 481-489
Bidwell, J.N.S. Automorphisms of direct products of finite groups II. Arch. Math. (Basel) 91 (2008) no. 2, 111-121.
An example of a theorem of the first one is:
Theorem. Let $G=H\times K$, where $H$ and $K$ have no common direct factor. Then $\mathrm{Aut}(G)\cong \mathcal{A}$, where
$$\mathcal{A} = \left.\left\{\left(\begin{array}{cc}\alpha&\beta\\\gamma&\delta\end{array}\right)\;\right|\; \alpha\in\mathrm{Aut}(H), \delta\in\mathrm{Aut}(K), \beta\in\mathrm{Hom}(K,Z(H)), \gamma\in\mathrm{Hom}(H,Z(K))\right\}.$$
In particular,
$$|\mathrm{Aut}(G)| = |\mathrm{Aut}(H)||\mathrm{Aut}(K)||\mathrm{Hom}(H,Z(K))||\mathrm{Hom}(K,Z(H))|.$$