How to deal with inactive students in a testing session?
It seems to me that students are permitted to spend exam time "as inactively as they choose," and that barring some truly exceptional edge cases it is neither fair to them nor the best use of your own time to try to deal with inactive students during the exam itself.

I'm sorry the behavior is stressful for you, but I don't have a good understanding of why.  Not working or writing on the exam is not an effective cheating technique; falling asleep or staring out the window less so.  If you see students with wandering eyes in a way that actually makes you concerned: okay, tell them not to do that when you catch them doing it.  But that's a problem of unwanted activity, not inactivity.  Moreover, you write


  Frequently the paper I get back is mostly blank after an hour of inactivity like this. 


I find it kind of strange that you think that a student (whom you know is registered for your class; no funny business there) who turns in a mostly blank exam is somehow cheating.  Cheating means trying to succeed through illegal means; if they are pathologically avoiding trying to succeed, I somehow doubt that cheating is the explanation.  

You write


  It puts me on edge because it's so inexplicable, 


Okay, I get you there: it certainly must be distressing as an instructor to witness students walking into an exam -- i.e., a situation which is a pressure-packed performance opportunity to most students -- and respond to the high pressure situation by basically doing nothing.  I agree that there's something going wrong here.  However, I don't think that you should fix the problem by proctoring the exam differently: rather, during the exam you should take note of which students are behaving in this way, and then make a point of talking to them about it after the exam (presumably after it's been graded rather than immediately at the end of the exam).  In my experience, if a student is otherwise even moderately engaged with the course (coming to class, turning in homework) then they are very likely to be responsive to such questions on the part of the instructor.  Maybe once in a blue moon you get a student who really doesn't want to work much on their exams and really doesn't want to talk to you about it.  OK: you tried, they didn't, they'll fail.  But they have the right to play it that way, it seems to me.

Let me end by commenting on another answer which suggests running future courses with a policy that says students' exams can be taken away from them if they are not working on them.  While clearly well-intentioned, I think that's a bad idea.  You simply do not have access to students' interior processes and you shouldn't pretend to do so: maybe a student who is staring out the window for half an hour is nevertheless working on the one problem that they don't know how to do and is going to write out solutions to all the problems in the last ten minutes.  (I mean, probably not, but maybe.)  It's just not defensible enough to respond to inactivity on an exam by taking the exam away from the student (and especially, with a policy to return it later on if they show suitable penitence).  A student who has an exam taken away can go to the department chair or the dean saying "My exam got taken away from me just because I was thinking rather than writing."  If I were the chair or the dean...c'mon: the student has a very strong case.