This code should work :
function refresh() {
window.location.reload(true);
}
var timer;
function start() {
timer = setTimeout(function(){refresh()}, 5000);
}
jQuery(document).ready(function() {
start();
jQuery('body').mouseenter(function() {
clearTimeout(timer);
}).mouseleave(function(e) {
var pageX = e.pageX || e.clientX,
pageY = e.pageY || e.clientY;
if(pageX <= 0 || pageY <= 0) {
start();
}else {
clearTimeout(timer);
}
});
});