Detecting Space-down on a mouse click

A

Aaron Fude

Hi,

The modifiers of the mouse-clicked event object tell me weather alt or shift
or ctrl key is down. What's the best way to detect whether some other key
(such as "Space" or "a") is down? The idea is to simulate the photoshop
feature that when alt and space are both pressed the active tool switches to
zoom.

I have a solution in mind where the overall frame captures the clicks and
stores it in some kind of global object, etc. But that seems overly
complicated for this simple task. Besides, I can't always control the JFrame
that my component will end up in.

Very many thanks in advance!

Aaron Fude
 
P

Paul Lutus

Aaron said:
Hi,

The modifiers of the mouse-clicked event object tell me weather alt or
shift or ctrl key is down. What's the best way to detect whether some
other key (such as "Space" or "a") is down?

There is an important distinction you need to make between alt/shift/ctrl
and space. The former are modifiers for keystrokes, the latter is a
keystroke event.

Because the latter is an event, and in reading your plan, I would say you do
not want to try to use it as you are doing.
The idea is to simulate the
photoshop feature that when alt and space are both pressed the active tool
switches to zoom.

So? Detect the same combination that Photoshop detects. Surely you don't
think the patent police will come after you for using the same keystroke
combination for your own purposes, do you?
I have a solution in mind where the overall frame captures the clicks and
stores it in some kind of global object, etc. But that seems overly
complicated for this simple task. Besides, I can't always control the
JFrame that my component will end up in.

Okay, fine. But you are much better off using a passive modifier like
alt/shift or some similar choice.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top