Yosef Karo, Translation:Shulchan Aruch — Yoreh Deah 285
“ There are those who say that when a person leaves his house, he puts his hand on the Mezuzah there and says “God will guard my going, etc.” And so too when one enters a house, one puts his hand on the Mezuzah. נתינתה בטפח החיצון.הגה: יש אומרים כשאדם יוצא מן הבית יניח ידו על המזוזה (מהרי"ל שם ומוכח בעבודת כוכבים דף יא) ויאמר "השם ישמר צאתי וגומר" (במדרש) . וכן כשיכנס אדם לבית -- יניח ידו על המזוזה. ”
