NAME
FLTK::events - Event types and data
Description
Event types and data. A Widget::handle() method needs this.
Functions
BUTTON
my $flags = FLTK::BUTTON( $number );-
The function
BUTTON(n)will turnnumber(1 .. 8) into the flag for a mouse button.Import this function with the
:eventstag.
belowmouse
my $under = FLTK::belowmouse( );-
Get the widget that is below the mouse. This is the last widget to respond to an
ENTERevent as long as the mouse is still pointing at it. This is for highlighting buttons and bringing up tooltips. It is not used to sendPUSHorMOVEdirectly, for several obscure reasons, but those events typically go to this widget.Import this function with the
:eventstag. FLTK::belowmouse( $widget );-
Change the
belowmouse()widget, the previous one and all parents (that don't contain the new widget) are sentLEAVEevents. Changing this does not sendENTERto this or any widget, because sendingENTERis supposed to test if the widget wants the mouse (by it returning non-zero from handle()).Import this function with the
:eventstag.
compose
my $changed = FLTK::compose( $del );-
Use of this function is very simple. Any text editing widget should call this for each
KEYevent.If a true value is returned, then it has modified the
event_text()andevent_length()to a set of bytes to insert (it may be of zero length!). It will also set thedelparameter to the number of bytes to the left of the cursor to delete, this is used to delete the results of the previous call tocompose(). Compose may consume the key, which is indicated by returning true, but both the length anddelare set to zero.Compose returns a false value if it thinks the key is a function key that the widget should handle itself, and not an attempt by the user to insert text.
Though the current implementation returns immediately, future versions may take quite awhile, as they may pop up a window or do other user-interface things to allow international characters to be selected.
Import this function with the
:eventstag.
compose_reset
FLTK::compose_reset( );-
If the user moves the cursor, be sure to call
compose_reset(). The next call tocompose()will start out in an initial state. In particular it will not set "del" to non-zero. This call is very fast so it is ok to call it many times and in many places.Import this function with the
:eventstag.
copy
FLTK::copy( $stuff, $length, $clipboard );-
Change the current selection. The block of text is copied to an internal buffer by FLTK (be careful if doing this in response to a
PASTEas this may be the same buffer returned byevent_text()).The block of text may be retrieved (from this program or whatever program last set it) with
paste().There are actually two buffers. If
clipboardis true then the text goes into the user-visible selection that is moved around with cut/copy/paste commands (on X this is the CLIPBOARD selection). Ifclipboardis false then the text goes into a less-visible buffer used for temporarily selecting text with the mouse and for drag & drop (on X this is the XA_PRIMARY selection).Import this function with the
:eventstag.
dnd
my $drag = FLTK::dnd( );-
Drag and drop the data set by the most recent
copy()(with theclipboardargument false). Returns true if the data was dropped on something that accepted it.By default only blocks of text are dragged. You can use system-specific variables to change the type of data.
Import this function with the
:eventstag.
event
event_button
-
Import this function with the
:eventstag.
event_clicks
FLTK::event_clicks( $i );-
Import this function with the
:eventstag. my $clicks = FLTK::event_clicks( );-
Import this function with the
:eventstag.
event_device
event_dx
event_dy
event_inside
my $in = FLTK::event_inside( $rectangle );-
Returns true if the current
event_x()andevent_y()put it inside the Rectangle. You should always call this rather than doing your own comparison so you are consistent about edge effects.Import this function with the
:eventstag.
event_is_click
my $click = FLTK::event_is_click( );-
Import this function with the
:eventstag. FLTK::event_is_click( $value );-
Import this function with the
:eventstag.
event_key
event_key_repeated
event_key_state
event_length
event_name
my $string = FLTK::event_name( $event );-
Return the corresponding name of an event, should not consume memory if api is not used. This is really only good for debugging.
Import this function with the
:eventstag.
event_pressure
event_state
my $state = FLTK::event_state( );-
Import this function with the
:eventstag. my $state = FLTK::event_state( $state );-
Import this function with the
:eventstag.
event_text
event_x
event_x_root
event_x_tilt
event_y
event_y_root
event_y_tilt
exit_modal
FLTK::exit_modal( );-
Turns on
exit_modal_flag(). This may be used by user callbacks to cancel modal state. See alsoWindow::make_exec_return().Import this function with the
:eventstag.
exit_modal_flag
my $eh = FLTK::exit_modal_flag( );-
True if
exit_modal()has been called. The flag is also set by the destruction or hiding of the modal widget, and on Windows by other applications taking the focus when grab is on.Import this function with the
:eventstag.
focus
my $widget = FLTK::focus( );-
Returns the widgets that will receive
KEYevents. This is undef if the application does not have focus now, or if no widgets accepted focus.Import this function with the
:eventstag. FLTK::focus( $widget );-
Change
focus()to the given widget, the previous widget and all parents (that don't contain the new widget) are sentUNFOCUSevents, the new widget is sent anFOCUSevent, and all parents of it getFOCUS_CHANGEevents.focus()is set whether or not the applicaton has the focus or if the widgets accept the focus. You may want to useFLTK::Widget::take_focus()instead, it will test first.Import this function with the
:eventstag.
foreachShortcut
my $value = FLTK::foreachShortcut( $SF, $widget );-
Calls the
handle()method from the passed ShortcutFunctor object for everyWidget::shortcut()assignment known. If any return true then this immediately returns that shortcut value, else this returns zero after calling it for the last one. This is most useful for making a display of shortcuts for the user, or implementing a shortcut editor.If
widgetis not null, only do assignments for that widget, this is much faster than searching the entire list. This is useful for drawing the shortcuts on a widget (though most fltk widgets only draw the first one).Import this function with the
:eventstag. my $value = FLTK::foreachShortcut( $SF );-
Same. But without widget NULL by default.
Import this function with the
:eventstag.
get_key_state
my $state = FLTK::get_key_state( $key );-
Returns true if the given key was held down (or pressed) during the last event. This is constant until the next event is read from the server. The possible values for the key are listed under
SpaceKey.Note: On Win32,
event_key_state(KeypadEnter)does not work.Import this function with the
:eventstag.
get_mouse
my @xy = FLTK::get_mouse( );-
Return where the mouse is on the screen by doing a round-trip query to the server. You should use
event_x_root()andevent_y_root()if possible, but this is necessary if you are not sure if a mouse event has been processed recently (such as to position your first window). If the display is not open, this will open it.Import this function with the
:eventstag.
grab
my $cvalue = FLTK::grab( );-
Returns the current value of grab (this is always false if
modal()is undef).Import this function with the
:eventstag.
handle
my $handled = FLTK::handle( $event, $window );-
This is the function called from the system-specific code for all events that can be passed to
Widget::handle().You can call it directly to fake events happening to your widgets. Currently data other than the event number can only be faked by writing to the undocumented
fltk::e_*variables, for instance to makeevent_x()return5, you whould dofltk::e_x = 5. This may change in future versions of fltk toolkit and is currently not supported by the FLTK module.This will redirect events to the
modal(),pushed(),belowmouse(), orfocus()widget depending on those settings and the event type. It will turnMOVEintoDRAGif any buttons are down. If the resulting widget returns 0 (or the window or widget is undef) then the functions pointed to byadd_event_handler()are called.
key
my $key = FLTK::key( $name );-
Turn a string into a
event_key()value or'd withevent_shift()flags. The returned value can be used by byFLTK::Widget::add_shortcut(). Any error, or a null or zero-length string, returns 0.Currently this understands prefixes of "Alt+", "Shift+", and "Ctrl+" to turn on
ALT,SHIFT, andCTRL. Case is ignored and the '+' can be a '-' instead and the prefixes can be in any order. You can also use '#' instead of "Alt+", '+' instead of "Shift+", and '^' instead of "Ctrl+".After the shift prefixes there can either be a single ASCII letter, "Fn" where
nis a number to indicate a function key, or "0xnnnn" to get an arbitraryevent_key()enumeration value.The inverse function to turn a number into a string is
key_name(). Currently this function does not parse some stringskey_name()can return, such as the names of arrow keys!Import this function with the
:eventstag.
key_name
my $string = FLTK::key_name( $hotkey );-
Unparse a
FLTK::Widget::shortcut(), anevent_key(), or anevent_key()or'd withevent_state(). Returns a human-readable string like "Alt+N". Ifhotkeyis zero an empty string is returned.The opposite function is
key().Import this function with the
:eventstag.
modal
FLTK::modal( $widget, $grab );-
Restricts events to a certain widget.
First thing: much of the time
Window::exec()will do what you want, so try using that.This function sets the passed widget as the "modal widget". All user events are directed to it or a child of it, preventing the user from messing with other widgets. The modal widget does not have to be visible or even a child of a Window for this to work (but if it not visible,
event_x()andevent_y()are meaningless, useevent_x_root()andevent_y_root()).The calling code is responsible for saving the current value of
modal()andgrab()and restoring them by calling this after it is done. The code calling this should then loop callingwait()untilexit_modal_flag()is set or you otherwise decide to get out of the modal state. It is the calling code's responsibility to monitor this flag and restore the modal widget to it's previous value when it turns on.grabindicates that the modal widget should get events from anywhere on the screen. This is done by messing with the window system. Ifexit_modal()is called in response to aPUSHevent (rather than waiting for the drag or release event) fltk will "repost" the event so that it is handled after modal state is exited. This may also be done for keystrokes in the future. On both X and WIN32 grab will not work unless you have some visible window because the system interface needs a visible window id. On X be careful that your program does not enter an infinite loop whilegrab()is on, it will lock up your screen!Import this function with the
:eventstag. my $current = FLTK::modal( );-
Returns the current modal widget, or undef if there isn't one. It is useful to test these in timeouts and file descriptor callbacks in order to block actions that should not happen while the modal window is up. You also need these in order to save and restore the modal state.
Import this function with the
:eventstag.
paste
FLTK::paste( $widget, $clipboard );-
This is what a widget does when a "paste" command (like Ctrl+V or the middle mouse click) is done to it. Cause a
PASTEevent to be sent to the receiver with the contents of the current selection in theevent_text(). The selection can be set bycopy().There are actually two buffers. If
clipboardis true then the text is from the user-visible selection that is moved around with cut/copy/paste commands (on X this is the CLIPBOARD selection). Ifclipboardis false then the text is from a less-visible buffer used for temporarily selecting text with the mouse and for drag & drop (on X this is the XA_PRIMARY selection).The reciever should be prepared to be called directly by this or, for it to happen later, or possibly not at all. This allows the window system to take as long as necessary to retrieve the paste buffer (or even to screw up completely) without complex and error-prone synchronization code most toolkits require.
Import this function with the
:eventstag.
pushed
my $current = FLTK::pushed( );-
Get the widget that is being pushed.
DRAGorRELEASE(and any morePUSH) events will be sent to this widget. This is null if no mouse button is being held down, or if no widget responded to thePUSHevent.Import this function with the
:eventstag. FLTK::pushed( $widget );-
Change the
pushed()widget. This sends no events.Import this function with the
:eventstag.
try_shortcut
my $handled = FLTK::try_shortcut( );-
Try sending the current
KEYevent as aSHORTCUTevent.Normally the
focus()gets all keystrokes, and shortcuts are only tested if that widget indicates it is uninterested by returning zero fromWidget::handle(). However in some cases the focus wants to use the keystroke only if it is not a shortcut. The most common example is Emacs-style editing keystrokes in text editing widgets, which conflict with Microsoft-compatable menu key bindings, but we want the editing keys to work if there is no conflict.This will send a
SHORTCUTevent just like the focus returned zero, to every widget in the focus window, and to theadd_handler()calls, if any. It will return true if any widgets were found that were interested in it. Ahandle()method can call this in aKEYevent. If it returns true, return 1 immediatly, as the shortcut will have executed and may very well have destroyed your widget. If this returns false, then do what you want the key to do.Import this function with the
:eventstag.
warp_mouse
my $worked = FLTK::warp_mouse( $x, $y );-
Change where the mouse is on the screen.
Returns true if successful, false on failure (exactly what success and failure means depends on the os).
Import this function with the
:eventstag.
Events
FLTK's event system passes numbered arguments to Widget::handle() and returns the same from event(). These events may be imported with the events tag and include the following:
NO_EVENTPUSHRELEASEENTERLEAVEDRAGFOCUSUNFOCUSKEYKEYUPFOCUS_CHANGEMOVESHORTCUTDEACTIVATEACTIVATEHIDESHOWPASTETIMEOUTMOUSEWHEELDND_ENTERDND_DRAGDND_LEAVEDND_RELEASETOOLTIP
If you're rolling your own event system (See FLTK::Subclass), you're gonna need these.
Event Keys
Values returned by event_key(), passed to event_key_state() and get_key_state(), and used for the low 16 bits of add_shortcut().
The actual values returned are based on X11 keysym values, though fltk always returns "unshifted" values much like Windows does. A given key always returns the same value no matter what shift keys are held down. Use event_text() to see the results of any shift keys.
The lowercase letters 'a' through 'z' and the ascii symbols '`', '-', '=', '[', ']', '\\', ',', '.', '/', ';', '\'' and space are used to identify the keys in the main keyboard.
On X systems unrecognized keys are returned unchanged as their X keysym value. If they have no keysym it uses the scan code or'd with 0x8000, this is what all those blue buttons on a Microsoft keyboard will do. I don't know how to get those buttons on Windows.
Supported keys may be imported with the events tag and include...
LeftButtonMiddleButtonRightButtonSpaceKeyBackSpaceKeyTabKeyClearKey-
On some systems with NumLock off '5' produces this.
ReturnKey-
Main Enter key, Windows and X documentation calls this "Return"
PauseKey-
Pause / Break button
ScrollLockKeyEscapeKeyHomeKeyLeftKeyUpKeyRightKeyDownKeyPageUpKeyPageDownKeyEndKeyPrintKey-
Print Scr / Sys Rq key
InsertKeyMenuKey-
Key in lower-right (between Ctrl and Win) with picture of popup menu
HelpKey-
Help key on Macintosh keyboards
NumLockKeyKeypad-
Add ASCII to this to get keypad keys.
As in
Keypad + "+"is the same asAddKey. KeypadEnter-
Enter on the keypad. Same as
Keypad + "\r" MultiplyKey-
*on the keypad. Same asKeypad + "*" AddKey-
+on the keypad. Same asKeypad + "+" SubtractKey-
-on the keypad. Same asKeypad + "-" DecimalKey-
.on the keypad DivideKey-
/on the keypad Keypad0-
0on the keypad Keypad1-
1on the keypad Keypad2-
2on the keypad Keypad3-
3on the keypad Keypad4-
4on the keypad Keypad5-
5on the keypad Keypad6-
6on the keypad Keypad7-
7on the keypad Keypad8-
8on the keypad Keypad9-
9on the keypad KeypadLast-
Keypad + '=', largest legal keypad key F0Key-
Add a number to get function key.
As in
F0Key + 3is the same asF3Key F1KeyF2KeyF3KeyF4KeyF5KeyF6KeyF7KeyF8KeyF9KeyF10KeyF11KeyF12KeyLastFunctionKey-
Largest legal function key. Same as
F0Key + 35 LeftShiftKey-
Left-hand Shift
RightShiftKey-
Right-hand Shift
LeftCtrlKey-
Left-hand Ctrl
RightCtrlKey-
Right-hand Ctrl
CapsLockKey-
Caps Lock
LeftMetaKey-
The left "Windows" or "Apple" key
RightMetaKey-
The right "Windows" or "Apple" key
LeftAltKey-
Left-hand Alt (option on Mac)
RightAltKey-
Right-hand Alt (option on Mac)
DeleteKey-
Delete
LeftAccKey-
Same as
LeftCtrlKeyon Mac,LeftAltKeyon other systems. RightAccKey-
Same as
RightCtrlKeyon Mac,RightAltKeyon other systems. LeftCmdKey-
Same as
LeftMetaKeyon Mac,LeftCtrlKeyon other systems. RightCmdKey-
Same as
RightMetaKeyon Mac,RightCtrlKeyon other systems.
...in addition to the above, letters a .. z and all punctuation are passed by their ordinal values.
Flags
Flags returned by event_state(), and used as the high 16 bits of Widget::add_shortcut() values (the low 16 bits are all zero, so these may be or'd with key values).
The function BUTTON(n) will turn n (1 .. 8) into the flag for a mouse button.
The current flags imported with the :events targ are...
SHIFT-
Either shift key held down
CAPSLOCK-
Caps lock is toggled on =item
CTRLEither ctrl key held down
ALT-
Either alt key held down
NUMLOCK-
Num Lock turned on.
META-
"Windows" or the "Apple" keys held down.
SCROLLLOCK-
Scroll Lock turned on.
BUTTON1-
Left mouse button held down.
BUTTON2-
Middle mouse button held down.
BUTTON3-
Right mouse button held down.
ANY_BUTTON-
Any mouse button (up to 8).
ACCELERATOR-
ALTon Windows/Linux,CTRLon OS/X, use for menu accelerators. COMMAND-
CTRLon Windows/Linux,METAon OS/X, use for menu shortcuts. OPTION-
ALT|METAon Windows/Linux, justALTon OS/X, use as a drag modifier.
Devices
Device identifiers are returned by event_device(). This is useful to get the device type that caused a PUSH, RELEASE, DRAG or MOVE event.
Current devices (which are imported with the events tag) include...
DEVICE_MOUSE-
Event triggered by the system mouse.
DEVICE_STYLUS-
Event triggered by a pen on a tablet, givin pressure and tilt information.
DEVICE_ERASER-
Event triggered by an eraser on a tablet, givin pressure and tilt information.
DEVICE_CURSOR-
Event triggered by a puck style device on a tablet.
DEVICE_AIRBRUSH-
Event triggered by an airbrush on a tablet, giving pressure and tilt information.
DEVICE_TOUCH-
Event triggered by touch a touch screen device.
Author
Sanko Robinson <sanko@cpan.org> - http://sankorobinson.com/
License and Legal
Copyright (C) 2008-2010 by Sanko Robinson <sanko@cpan.org>
This program is free software; you can redistribute it and/or modify it under the terms of The Artistic License 2.0. See the LICENSE file included with this distribution or notes on the Artistic License 2.0 for clarification.
When separated from the distribution, all original POD documentation is covered by the Creative Commons Attribution-Share Alike 3.0 License. See the clarification of the CCA-SA3.0.