Re: Changing WIDGET_BUTTON behaviour [message #62448] |
Tue, 09 September 2008 08:57 |
Spon
Messages: 178 Registered: September 2007
|
Senior Member |
|
|
On Sep 9, 3:16 pm, Thiago Biscaro <tsbisc...@gmail.com> wrote:
> There's 2 ways of pressing a button created by the WIDGET_BUTTON
> method: pressing spacebar, or clicking with any mouse button.
>
> Is there a way to activate the button using the enter (carriage
> return) key? It's really annoying and counterintuitive not have this
> functionality implemented.
Short of building your own 'pseudobuttons' out of draw widgets, I
don't see a simple way of implementing this, as button widgets do not
accept the Keyboard_Events keyword.
After having prodded it myself for a while, I had a trawl through
David's site and it threw up this:
http://www.dfanning.com/widget_tips/keyboard_events.html
which may be more useful.
Regards,
Chris
; Here's how I went about it:
PRO PSEUDOBUTTON_PRESS
PRINT, 'Button has been pressed!'
END
PRO PSEUDOBUTTON_EVENT, Event
; Mouse click press
IF Event.Type EQ 0 $
; Keyboard event
OR (Event.Type EQ 5 $
; Enter key
AND Event.Ch EQ 13 $
; Pressed, not released
AND Event.Press) $
THEN PSEUDOBUTTON_PRESS
END
PRO PSEUDOBUTTON
TLB = WIDGET_BASE(COLUMN = 1)
BTN = WIDGET_DRAW(TLB, /BUTTON_EVENTS, $
KEYBOARD_EVENTS = 1)
WIDGET_CONTROL, TLB, /REALIZE
WIDGET_CONTROL, BTN, GET_VALUE = WIndex
WSET, WIndex
XYOUTS, 0.1, 0.1, 'Button'
XMANAGER, 'PSEUDOBUTTON', TLB
END
|
|
|