Re: How to get the position of mouse [message #32737] |
Tue, 05 November 2002 06:04 |
Roberto Monaco
Messages: 11 Registered: August 2002
|
Junior Member |
|
|
(a) If you are within an event handler xxx (motion, or click events), the
information you need is in the structure event:
PRO xxx, event
...
mouse_x = event.x
mouse_y = event.y
...
Look at event.press and event.release if you want to know which button was
pressed - these are bitmaps (0=none motion-event, 1=left, 2=center, 4=right)
(b) if you call the function cursor, you pass two variables (x,y) that in
return contain the position of the mouse - the structure !mouse.button
contains the bitmap as above
Regards,
Roberto
"lily_zhang" <fengliza@sina.com> wrote in message
news:19870040.0211050436.2105e396@posting.google.com...
> I display an image on the screen first, and then intend to get the
> coordinate of mouse when I depress the left button of it. Would you
> tell me how to realize it?
|
|
|
Re: How to get the position of mouse [message #32739 is a reply to message #32737] |
Tue, 05 November 2002 05:27  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
lily_zhang (fengliza@sina.com) writes:
> I display an image on the screen first, and then intend to get the
> coordinate of mouse when I depress the left button of it. Would you
> tell me how to realize it?
In a regular graphics window, you would do something like
this:
Window
TV, image
Cursor, x, y, /Down
IF !Mouse EQ 1 THEN Print, 'You pressed LEFT button.'
But, typically, if you are asking for user input, you
will be doing this in a draw widget window, in which case
you will turn button events on for the window, and then
process the event in an event handler like this:
possibleEvents = ['DOWN', 'UP', 'MOTION']
whichButton = ['NONE', 'LEFT', 'MIDDLE', 'NONE', 'RIGHT']
thisEvent = possibleEvents[event.type]
buttonPressed = whichButton[event.press]
IF thisEvent EQ 'DOWN' THEN Print, 'You pressed the ' + $
buttonPressed + ' button down.'
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|