In
programming and
software design
Software design is the process by which an agent creates a specification of a software artifact intended to accomplish goals, using a set of primitive components and subject to constraints. Software design may refer to either "all the activity ...
, an event is an action or occurrence recognized by
software
Software is a set of computer programs and associated documentation and data. This is in contrast to hardware, from which the system is built and which actually performs the work.
At the lowest programming level, executable code consists ...
, often originating
asynchronously from the external environment, that may be
handled by the software. Computer events can be generated or triggered by the system, by the
user
Ancient Egyptian roles
* User (ancient Egyptian official), an ancient Egyptian nomarch (governor) of the Eighth Dynasty
* Useramen, an ancient Egyptian vizier also called "User"
Other uses
* User (computing), a person (or software) using an ...
, or in other ways. Typically, events are handled
synchronously with the
program flow
In computer science, control flow (or flow of control) is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated. The emphasis on explicit control flow distinguishes an ''imper ...
; that is, the software may have one or more dedicated places where events are handled, frequently an
event loop In computer science, the event loop is a programming construct or design pattern that waits for and dispatches events or messages in a program. The event loop works by making a request to some internal or external "event provider" (that generally ...
.
A source of events includes the user, who may
interact
Advocates for Informed Choice, dba interACT or interACT Advocates for Intersex Youth, is a 501(c)(3) nonprofit organization using innovative strategies to advocate for the legal and human rights of children with intersex traits. The organizati ...
with the software through the computer's
peripheral
A peripheral or peripheral device is an auxiliary device used to put information into and get information out of a computer. The term ''peripheral device'' refers to all hardware components that are attached to a computer and are controlled by the ...
s - for example, by typing on the
keyboard
Keyboard may refer to:
Text input
* Keyboard, part of a typewriter
* Computer keyboard
** Keyboard layout, the software control of computer keyboards and their mapping
** Keyboard technology, computer keyboard hardware and firmware
Music
* Musi ...
. Another source is a
hardware device such as a
timer
A timer is a specialized type of clock used for measuring specific time intervals.
Timers can be categorized into two main types.
The word "timer" is usually reserved for devices that counts down from a specified time interval, while devices th ...
. Software can also trigger its own set of events into the event loop, e.g. to communicate the completion of a task. Software that changes its behavior in response to events is said to be
event-driven
Event driven may refer to:
The term event-driven refers to a methodology that focuses on events and event dependencies.
Examples include
* Event-driven finite-state machine, finite-state machine where the transition from one state to another i ...
, often with the goal of being
interactive
Across the many fields concerned with interactivity, including information science, computer science, human-computer interaction, communication, and industrial design, there is little agreement over the meaning of the term "interactivity", but mo ...
.
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 In computer science, the event loop is a programming construct or design pattern that waits for and dispatches events or messages in a program. The event loop works by making a request to some internal or external "event provider" (that generally ...
, 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
instruction set
In computer science, an instruction set architecture (ISA), also called computer architecture, is an abstract model of a computer. A device that executes instructions described by that ISA, such as a central processing unit (CPU), is called an ' ...
level, where they complement
interrupt
In digital computers, an interrupt (sometimes referred to as a trap) is a request for the processor to ''interrupt'' currently executing code (when permitted), so that the event can be processed in a timely manner. If the request is accepted, ...
s. Compared to interrupts, events are normally implemented synchronously: the program explicitly waits for an event to be generated and handled (typically by calling an instruction that dispatches the next event), whereas an interrupt can demand immediate service.
Delegate event model
A common variant in
object-oriented programming
Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of pr ...
is the
delegate event model, which is provided by some
graphic user interface
The GUI ( "UI" by itself is still usually pronounced . or ), graphical user interface, is a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicator such as primary notation, inste ...
s. This model is based on three entities:
* a control, which is the event source
*
listeners
is an original Japanese anime television series produced by MAPPA, created by Jin, and directed by Hiroaki Ando. The series aired from April 3 to June 19, 2020 on the Animeism programming block.
Plot
The series is set in a post-apocalyptic wor ...
, also called
event handler
In programming and software design, an event is an action or occurrence recognized by software, often originating asynchronously from the external environment, that may be handled by the software. Computer events can be generated or triggered ...
s, that receive the event notification from the source
*
interfaces
Interface or interfacing may refer to:
Academic journals
* Interface (journal), ''Interface'' (journal), by the Electrochemical Society
* ''Interface, Journal of Applied Linguistics'', now merged with ''ITL International Journal of Applied Lin ...
(in the broader meaning of the term) that describe the
protocol
Protocol may refer to:
Sociology and politics
* Protocol (politics), a formal agreement between nation states
* Protocol (diplomacy), the etiquette of diplomacy and affairs of state
* Etiquette, a code of personal behavior
Science and technology
...
by which the event is to be communicated.
Furthermore, the model requires that:
* every listener must implement the interface for the
event
Event may refer to:
Gatherings of people
* Ceremony, an event of ritual significance, performed on a special occasion
* Convention (meeting), a gathering of individuals engaged in some common interest
* Event management, the organization of eve ...
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
Abstraction in its main sense is a conceptual process wherein general rules and concepts are derived from the usage and classification of specific examples, literal ("real" or "concrete") signifiers, first principles, or other methods.
"An abstr ...
, for example:
delegate void Notifier (string sender);
class Model
class View1
class View2
class Test
Event handler
In computer programming, an ''event handler'' may be implemented using a
callback
Callback may refer to:
* Callback (comedy), a joke which refers to one previously told
* Callback (computer programming), executable code that is passed as a parameter to other code
* Callback (telecommunications), the telecommunications event tha ...
subroutine
In computer programming, a function or subroutine is a sequence of program instructions that performs a specific task, packaged as a unit. This unit can then be used in programs wherever that particular task should be performed.
Functions may ...
that handles inputs received in a program (called a listener in
Java
Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
and
JavaScript
JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
). Each ''event'' is a piece of application-level information from the underlying
framework
A framework is a generic term commonly referring to an essential supporting structure which other things are built on top of.
Framework may refer to:
Computing
* Application framework, used to implement the structure of an application for an op ...
, typically the
GUI toolkit
The GUI ( "UI" by itself is still usually pronounced . or ), graphical user interface, is a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicator such as primary notation, inste ...
. GUI events include
key
Key or The Key may refer to:
Common meanings
* Key (cryptography), a piece of information that controls the operation of a cryptography algorithm
* Key (lock), device used to control access to places or facilities restricted by a lock
* Key (map ...
presses,
mouse
A mouse ( : mice) is a small rodent. Characteristically, mice are known to have a pointed snout, small rounded ears, a body-length scaly tail, and a high breeding rate. The best known mouse species is the common house mouse (''Mus musculus' ...
movement, action selections, and
timer
A timer is a specialized type of clock used for measuring specific time intervals.
Timers can be categorized into two main types.
The word "timer" is usually reserved for devices that counts down from a specified time interval, while devices th ...
s expiring. On a lower level, events can represent availability of new data for reading a file or network stream. Event handlers are a central concept in
event-driven programming
In computer programming, event-driven programming is a programming paradigm in which the flow of the program is determined by events such as user actions ( mouse clicks, key presses), sensor outputs, or message passing from other programs or t ...
.
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
interrupts
In digital computers, an interrupt (sometimes referred to as a trap) is a request for the processor to ''interrupt'' currently executing code (when permitted), so that the event can be processed in a timely manner. If the request is accepted, ...
generated by hardware devices, software interrupt instructions, or state changes in
polling
Poll, polled, or polling may refer to:
Figurative head counts
* Poll, a formal election
** Election verification exit poll, a survey taken to verify election counts
** Polling, voting to make decisions or determine opinions
** Polling places o ...
. On this level,
interrupt handler
In computer systems programming, an interrupt handler, also known as an interrupt service routine or ISR, is a special block of code associated with a specific interrupt condition. Interrupt handlers are initiated by hardware interrupts, softwar ...
s and
signal handler
Signals are standardized messages sent to a running program to trigger specific behavior, such as quitting or error handling. They are a limited form of inter-process communication (IPC), typically used in Unix, Unix-like, and other POSIX-compli ...
s correspond to event handlers.
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
communication
Communication (from la, communicare, meaning "to share" or "to be in relation with") is usually defined as the transmission of information. The term may also refer to the message communicated through such transmissions or the field of inquir ...
s
software
Software is a set of computer programs and associated documentation and data. This is in contrast to hardware, from which the system is built and which actually performs the work.
At the lowest programming level, executable code consists ...
for linking applications that generate small
messages
A message is a discrete unit of communication intended by the source for consumption by some recipient or group of recipients. A message may be delivered by various means, including courier, telegraphy, carrier pigeon and electronic bus.
A ...
(the "events") to applications that monitor the associated conditions and may take actions triggered by events.
Event notification is an important feature in modern
database
In computing, a database is an organized collection of data stored and accessed electronically. Small databases can be stored on a file system, while large databases are hosted on computer clusters or cloud storage. The design of databases sp ...
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
publish-subscribe, a term that relates to one class of products supporting event notification in networked settings. The
virtual synchrony
A reliable multicast is any computer networking protocol that provides a '' reliable'' sequence of packets to multiple recipients simultaneously, making it suitable for applications such as multi-receiver file transfer.
Overview
Multicast is a net ...
model is sometimes used to endow event notification systems, and publish-subscribe systems, with stronger fault-tolerance and consistency guarantees.
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
A pointing device is a human interface device that allows a user to input spatial (i.e., continuous and multi-dimensional) data to a computer. CAD systems and graphical user interfaces (GUI) allow the user to control and provide data to t ...
can generate a number of software recognisable
pointing device gesture
In computing, a pointing device gesture or mouse gesture (or simply gesture) is a way of combining pointing device or finger movements and clicks that the software recognizes as a specific computer event and responds to accordingly. They can be ...
s. 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
[Mouse and Keyboard Events in Windows Forms](_blank)
Microsoft. Retrieved on February 12, 2008. and
mouse wheel motion, or a combination of these gestures. For example,
double-click
A double-click is the act of pressing a computer mouse button twice quickly without moving the mouse. Double-clicking allows two different actions to be associated with the same mouse button. It was developed by Bill Atkinson of Apple Computer (n ...
s commonly select words and characters within boundary, and
triple-click
Triple-click is the action of clicking a computer mouse button three times quickly without moving the mouse. Along with clicking and double-clicking, triple-clicking allows three different actions to be associated with the same mouse button. Dou ...
s 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.
Joystick events
Moving a
joystick
A joystick, sometimes called a flight stick, is an input device consisting of a stick that pivots on a base and reports its angle or direction to the device it is controlling. A joystick, also known as the control column, is the principal cont ...
generates an X-Y analogue signal. They often have multiple buttons to trigger events. Some
gamepad
A gamepad is a type of video game controller held in two hands, where the fingers (especially thumbs) are used to provide input. They are typically the main input device for video game consoles.
Features
Gamepads generally feature a set of ...
s for popular game boxes use joysticks.
Touchscreen events
The events generated using a
touchscreen
A touchscreen or touch screen is the assembly of both an input ('touch panel') and output ('display') device. The touch panel is normally layered on the top of an electronic visual display of an information processing system. The display is often ...
are commonly referred to as
touch event
DOM (Document Object Model) Events are a signal that something has occurred, or is occurring, and can be triggered by user interactions or by the browser. Client-side scripting languages like JavaScript, JScript, ECMAScript, VBScript, and Java (pro ...
s or
gesture
A gesture is a form of non-verbal communication or non-vocal communication in which visible bodily actions communicate particular messages, either in place of, or in conjunction with, speech. Gestures include movement of the hands, face, or ot ...
s.
Device events
Device events include action by or to a device, such as a shake, tilt, rotation, move etc.
See also
*
Callback (computer programming)
In computer programming, a callback or callback function is any reference to executable code that is passed as an argument to another piece of code; that code is expected to ''call back'' (execute) the callback function as part of its job. This ...
*
Database trigger A database trigger is procedural code that is automatically executed in response to certain events on a particular table or view in a database. The trigger is mostly used for maintaining the integrity of the information on the database. For example ...
*
DOM events
*
Event-driven programming
In computer programming, event-driven programming is a programming paradigm in which the flow of the program is determined by events such as user actions ( mouse clicks, key presses), sensor outputs, or message passing from other programs or t ...
*
Exception handling
In computing and computer programming, exception handling is the process of responding to the occurrence of ''exceptions'' – anomalous or exceptional conditions requiring special processing – during the execution of a program. In general, an ...
*
Interrupt handler
In computer systems programming, an interrupt handler, also known as an interrupt service routine or ISR, is a special block of code associated with a specific interrupt condition. Interrupt handlers are initiated by hardware interrupts, softwar ...
*
Interrupt
In digital computers, an interrupt (sometimes referred to as a trap) is a request for the processor to ''interrupt'' currently executing code (when permitted), so that the event can be processed in a timely manner. If the request is accepted, ...
s
*
Observer pattern
In software design and engineering, the observer pattern is a software design pattern in which an object, named the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by ca ...
(e.g., Event listener)
*
Reactor pattern
The reactor design pattern is an event handling pattern for handling service requests delivered concurrently to a service handler by one or more inputs. The service handler then demultiplexes the incoming requests and dispatches them synchronous ...
vs.
Proactor pattern Proactor is a software design pattern for event handling in which long running activities are running in an asynchronous part. A ''completion handler'' is called after the asynchronous part has terminated.
The proactor pattern can be considered to ...
*
Signal programming
Signal programming is used in the same sense as dataflow programming, and is similar to event-driven programming.
The word signal is used instead of the word dataflow in documentation of such libraries as Qt, GTK+ and libsigc++. The time instan ...
*
Virtual synchrony
A reliable multicast is any computer networking protocol that provides a '' reliable'' sequence of packets to multiple recipients simultaneously, making it suitable for applications such as multi-receiver file transfer.
Overview
Multicast is a net ...
References
External links
* Article
Event Handlers and Callback Functions'
Distributed Events and Notifications*
Javadoc
Javadoc (originally cased JavaDoc) is a documentation generator created by Sun Microsystems for the Java language (now owned by Oracle Corporation) for generating API documentation in HTML format from Java source code. The HTML format is used for ...
documentation
* Java package Javadoc API documentation
*
Java package A Java package organizes Java classes into namespaces,
providing a unique namespace for each type it contains.
Classes in the same package can access each other's package-private and protected members.
In general, a package can contain the follo ...
Javadoc API documentation
Write an Event Handler
{{DEFAULTSORT:Event (Computing)
Computer programming
Subroutines