Event (computing)
In
The user can be the source of an event. The user may
Description
Event driven systems are typically used when there is some asynchronous external activity that needs to be handled by a program; for example, a user who presses a button on their mouse. An event driven system typically runs an event loop, that keeps waiting for such activities, e.g. input from devices or internal alarms. When one of these occurs, it collects data about the event and dispatches the event to the event handler software that will deal with it.
A program can choose to ignore events, and there may be libraries to dispatch an event to multiple handlers that may be programmed to listen for a particular event. The data associated with an event at a minimum specifies what type of event it is, but may include other information such as when it occurred, who or what caused it to occur, and extra data provided by the event source to the handler about how the event should be processed.
Events are typically used in user interfaces, where actions in the outside world (mouse clicks, window-resizing, keyboard presses, messages from other programs, etc.) are handled by the program as a series of events. Programs written for many windowing environments consist predominantly of event handlers.
Events can also be used at
User-generated events
There are a large number of situations or events that a program or system may generate or respond to. Some common user generated events include:
Mouse events
A pointing device can generate a number of software recognisable pointing device gestures. A mouse can generate a number of mouse events, such as mouse move (including direction of move and distance), mouse left/right button up/down[1] and mouse wheel motion, or a combination of these gestures. For example, double-clicks commonly select words and characters within boundary, and triple-clicks entire paragraphs.
Keyboard events
Pressing a key on a keyboard or a combination of keys generates a keyboard event, enabling the program currently running to respond to the introduced data such as which key/s the user pressed.[1]
Joystick events
Moving a joystick generates an X-Y analogue signal. They often have multiple buttons to trigger events. Some gamepads for popular game boxes use joysticks.
Touchscreen events
The events generated using a
Device events
Device events include action by or to a device, such as a shake, tilt, rotation, move etc.
Delegate event model
A common variant in
- a control, which is the event source
- event handlers, that receive the event notification from the source
- protocolby which the event is to be communicated.
Furthermore, the model requires that:
- every listener must implement the interface for the event it wants to listen to
- every listener must register with the source to declare its desire to listen to the event
- every time the source generates the event, it communicates it to the registered listeners, following the protocol of the interface.
C# uses events as special delegates that can only be fired by the class that declares it. This allows for better abstraction, for example:[2]
delegate void Notifier (string sender);
class Model
{
public event Notifier notifyViews;
public void Change() { ... notifyViews("Model"); }
}
class View1
{
public View1(Model model)
{
model.notifyViews += new Notifier(this.Update1);
}
void Update1(string sender)
{
Console.WriteLine($"{sender} was changed during update");
}
}
class View2
{
public View2(Model model)
{
model.notifyViews += new Notifier(this.Update2);
}
void Update2(string sender)
{
Console.WriteLine($"{sender} was changed");
}
}
class Test
{
static void Main()
{
Model model = new Model();
new View1(model);
new View2(model);
model.Change();
}
}
Event handler
In computer programming, an event handler may be implemented using a
The events are created by the framework based on interpreting lower-level inputs, which may be lower-level events themselves. For example, mouse movements and clicks are interpreted as menu selections. The events initially originate from actions on the operating system level, such as
Created events are first processed by an event dispatcher within the framework. It typically manages the associations between events and event handlers, and may queue event handlers or events for later processing. Event dispatchers may call event handlers directly, or wait for events to be dequeued with information about the handler to be executed.
Event notification
Event notification is a term used in conjunction with
Event notification is an important feature in modern database systems (used to inform applications when conditions they are watching for have occurred), modern operating systems (used to inform applications when they should take some action, such as refreshing a window), and modern distributed systems, where the producer of an event might be on a different machine than the consumer, or consumers. Event notification platforms are normally designed so that the application producing events does not need to know which applications will consume them, or even how many applications will monitor the event stream.
It is sometimes used as a synonym for
See also
- Callback (computer programming)
- Database trigger
- DOM events
- Event-driven programming
- Exception handling
- Interrupt handler
- Interrupts
- Observer pattern (e.g., Event listener)
- Reactor pattern vs. Proactor pattern
- Signal programming
- Virtual synchrony
References
- ^ a b Mouse and Keyboard Events in Windows Forms. Microsoft. Retrieved on February 12, 2008.
- ^ Mössenböck, Hanspeter (2002-03-25). "Advanced C#: Variable Number of Parameters" (PDF). Institut für Systemsoftware, Johannes Kepler Universität Linz, Fachbereich Informatik. p. 26. Retrieved 2011-08-05.
- ^ "EventTarget.addEventListener() - Web APIs | MDN". developer.mozilla.org. 11 March 2024.
External links
- Article Event Handlers and Callback Functions
- A High Level Design of the Sub-Farm Event Handler
- An Events Syntax for XML
- Distributed Events and Notifications
- Event order
Java DOM Interface Event
Javadoc documentationjava.awt.event
Java package Javadoc API documentationjavax.swing.event
Java package Javadoc API documentation- Write an Event Handler