comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: keyboard events with WIDGET_DRAW
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: keyboard events with WIDGET_DRAW [message #15994] Tue, 22 June 1999 00:00
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
David Mattes (dmattes@u.washington.edu) writes:

> does anyone know how to capture keyboard events when a draw widget has
> focus??? i'd like to be able to use keypresses as shortcuts when someone
> is using the mouse inside the draw widget.

This is not the sort of thing that can usually be done
with widgets. However, J.D. Smith came up with a clever
hack that works surprisingly well. I wrote an article
about it that you can find here:

http://www.dfanning.com/tips/keyboard_events.html

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: keyboard events with WIDGET_DRAW [message #15996 is a reply to message #15994] Tue, 22 June 1999 00:00 Go to previous message
Liam Gumley is currently offline  Liam Gumley
Messages: 473
Registered: November 1994
Senior Member
"D. Mattes" wrote:
> does anyone know how to capture keyboard events when a draw widget has
> focus??? i'd like to be able to use keypresses as shortcuts when someone
> is using the mouse inside the draw widget.

I don't think that you can capture keyboard events while a draw widget
has focus. The workaround suggested in this group (I don't recall who it
was) is to create a hidden text widget behind the draw widget, and then
set the input focus to the text widget whenever you want to capture
keyboard events. The following untested code snippet gives an example:

;- Create widgets

tlb = widget_base()
text = widget_text(tlb, scr_xsize=1, scr_ysize=1, /all, uvalue='Hidden')
draw = widget_draw(tlb, scr_xsize=256, scr_ysize=256, uvalue='Draw')
widget_control, tlb, /realize

;- Set input focus to hidden text widget to capture keyboard events

widget_control, text, input_focus=1

As long as the text widget has focus, you should capture text events.
The event structure item EVENT.CH will contain the ASCII code of the
pressed key. Unfortunately IDL doesn't seem to understand the difference
between Control-{key} and {key}.

Cheers,
Liam.

PS Notice how my example does not use pointers.....

--
Liam E. Gumley
Space Science and Engineering Center, UW-Madison
http://cimss.ssec.wisc.edu/~gumley
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: undefined procedure problem
Next Topic: Colors again!

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 06:09:42 PDT 2025

Total time taken to generate the page: 1.36009 seconds