How to detect shift down

Ross Boylan RossBoylan at stanfordalumni.org
Fri Apr 26 23:53:51 UTC 2002


On Wed, Apr 24, 2002 at 11:27:55AM +0200, Andreas Raab wrote:
> > > 	ActiveEvent shiftPressed.
> >
> > That still doesn't seem to work.  The code I put this in (before a
> > halt) never halted, though I sat on the shift key.  When I test in a
> > workspace (Delay forSeconds: 1) wait. ActiveEvent
> anyModifierKeyPressed 
> > is always true, but shiftPressed is always false.  One possible
> > explanation is that the relevant event is the one causing the
> > evaluation (alt-p). 
> 
> Well, yes, of course! ActiveEvent is the event that is currently handled
> so if you hit Alt-P it's gonna be Alt-P ;-) What else would you expect?
> 
> > But at any rate I still can't get a hold of the
> > current keyboard state.
> 
> Then, maybe you should explain where you need to use it. It appears to
> me that if you are in some Morphic environment ActiveEvent will give you
> exactly what you'd expect. As an example, you might try to select
> 	ActiveEvent shiftPressed.
> then right-click to get the context menu, then press the shift key, and
> release the mouse over the "printIt" entry. It should say "true" as a
> result (at least it does so on my machine).
> 
> Cheers,
>   - Andreas
> 
> 

I've actually fixed the original thing I was trying to debug, but I'd
still like to know how to do this.  In that case Morphic stepping was
causing certain methods to execute, and I wanted to break into them to
see what was happening.  I couldn't put a self halt, because that
would have put me in a nearly infinite loop.

In my current real-world testing, the process context is a bit
different: I have a background process that periodically wakes and
executes a method.

I tried putting

  ActiveEvent shiftPressed ifTrue: [self halt.].

into that method. This doesn't quite work; it produces an error
because ActiveEvent is nil.

So I'm trying to find a way to detect if the shift key is pressed at
the instanct the method is executing.  Does the VM design make this
difficult (e.g, the shift down is reported as an even, and if you
aren't in line to catch it you're just not going to find out), or am I
just missing an easy solution?

Thanks.


(P.S. My original fix to the debugging problem consisted of adding a
state variable to prevent the halt from happening more than once.  It
worked, but it was cumbersome.)



More information about the Squeak-dev mailing list