6.4.3 Events
There are several event types (other event types can be defined as needed, but
existing set covers all current CSWS needs). There is the base event
class called `csEvent'. It has several public data fields, the mostly
used is Type which contains the event type. There are following currently
defined event types:
csevNothing
- The so-called "empty" event; mostly used internally by CSWS.
csevKeyDown
- Key has been pressed event.
csevKeyUp
- Key has been released event. On `csevKeyUp' and `csevKeyDown'
events the following data fields in event object are also valid:
Key.Code
- Contains code of key that has been pressed or released. It can be a literal
value (`A', `z', `$') or one of predefined
`CSKEY_XXX' values (`CSKEY_UP', `CSKEY_ESC',
`CSKEY_SPACE', `CSKEY_ENTER', etc.).
Key.Modifiers
- Contains the state of shift keys at time when this event has been generated.
Note that it not necessarily is the same as current key state. To decode its
value you should use the pre-defined `CSMASK_XXX' constants. For
example to check if the Alt modifier was pressed, and only this
modifier you might use this code:
| if ((Event.Key.Modifiers & CSMASK_ALLSHIFTS) ==
CSMASK_ALT)
{
... ALT + Event.Key.Code pressed ...
}
|
Or, alternately, to check if Alt was pressed, but not necessarily
the only modifier key pressed, you could do it this way:
| if (Event.Key.Modifiers & CSMASK_ALT)
{
... (at least ALT) + Event.Key.Code pressed ...
}
|
Also there is a bit in `Modifiers' called `CSMASK_FIRST' that is set
only when key is pressed for first time. With this you can separate actual
key presses from autorepeated keyboard events.
csevMouseMove
- Mouse moved event.
csevMouseDown
- A mouse button was pressed event.
csevMouseUp
- A mouse button was released event. On all mouse events the following data
fields in event object are also valid:
Mouse.x
Mouse.y
- The screen position where mouse event happened. Mouse position is always
converted to component coordinate system, i.e. `Mouse.x == 0' and
`Mouse.y == 0' means that mouse is at component top-left system.
Button
- Mouse button number, counting from 1. Not valid for "mouse moved" event.
Key.Modifiers
- Contains the state of shift keys at time when this event has been generated.
See above for comments on shift keys.
csevCommand
- A command event. Command events are generated by windowing system components,
not by hardware. For example, when a button is pressed, it sends a command
event with some command code to its parent component. There is only one data
field for this type of events called `Info' of type `void*'. It can
point to any event-related information.
csevBroadcast
- Broadcast events are much like command events, except that no component can
intercept (eat) it, and they are feed to all child, grandchild etc.
components in a component tree (starting from the component that received
first this event).
To check if the event is generated by keyboard, you can use the predefined
CS_IS_KEYBOARD_EVENT(Event)
macro. To check for mouse events, you can use
the CS_IS_MOUSE_EVENT(Event)
macro.
This document was generated using
texi2html