xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Public Member Functions | List of all members
xtd::forms::key_event_args Class Reference

#include <key_event_args.h>

Definition

Provides data for the key_down or key_up event.

Namespace
xtd::forms
Library
xtd.forms
Remarks
A key_event_args, which specifies the key the user pressed and whether any modifier keys (CMD, CTRL, ALT, and SHIFT) were pressed at the same time, is passed with each key_down or key_up event.
The key_down event occurs when the user presses any key. The key_up event occurs when the user releases the key. Duplicate key_down events occur each time the key repeats, if the key is held down, but only one key_up event is generated when the user releases the key.
The key_press event also occurs when a key is pressed. A key_press_event_args is passed with each key_press event, and specifies the character that was composed as a result of each key press.

Public Member Functions

 key_event_args ()=default
 Initializes a new instance of the key_event_args class. More...
 
 key_event_args (xtd::forms::keys key_data)
 Initializes a new instance of the key_event_args class. More...
 
bool alt () const
 Gets a value indicating whether the ALT key was pressed. More...
 
bool command () const
 Gets a value indicating whether the CMD key was pressed. More...
 
bool control () const
 Gets a value indicating whether the CTRL key was pressed. More...
 
bool handled () const
 Gets a value indicating whether the event was handled. More...
 
void handled (bool handled)
 Sets a value indicating whether the event was handled. More...
 
keys key_code () const
 Gets the keyboard code for a key_down or key_up event. More...
 
keys key_data () const
 Gets the key data for a key_down or key_up event. More...
 
int key_value () const
 Gets the keyboard value for a key_down or key_up event. More...
 
keys modifiers () const
 Gets the modifier flags for a key_down or key_up event. The flags indicate which combination of CMD, CTRL, SHIFT, and ALT keys was pressed. More...
 
bool shift () const
 Gets a value indicating whether the SHIFT key was pressed. More...
 
bool suppress_key_press () const
 Gets a value indicating whether the key event should be passed on to the underlying control. More...
 
void suppress_key_press (bool suppress_key_press)
 Sets a value indicating whether the key event should be passed on to the underlying control. More...
 
- Public Member Functions inherited from xtd::event_args
 event_args ()=default
 Initializes a new instance of the event_args class. More...
 
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object. More...
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object. More...
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type. More...
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const
 Gets the type of the current instance. More...
 
virtual xtd::ustring to_string () const noexcept
 Returns a std::string that represents the current object. More...
 

Additional Inherited Members

- Static Public Attributes inherited from xtd::event_args
static const event_args empty
 Provides a value to use with events that do not have event data. More...
 
- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal. More...
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance. More...
 

Constructor & Destructor Documentation

◆ key_event_args() [1/2]

xtd::forms::key_event_args::key_event_args ( )
default

Initializes a new instance of the key_event_args class.

◆ key_event_args() [2/2]

xtd::forms::key_event_args::key_event_args ( xtd::forms::keys  key_data)
inline

Initializes a new instance of the key_event_args class.

Parameters
key_dataA xtd::forms::keys representing the key that was pressed, combined with any modifier flags that indicate which CMD, CTRL, SHIFT, and ALT keys were pressed at the same time. Possible values are obtained by applying the bitwise OR (|) operator to constants from the Keys enumeration.

Member Function Documentation

◆ alt()

bool xtd::forms::key_event_args::alt ( ) const
inline

Gets a value indicating whether the ALT key was pressed.

Returns
true if the ALT key was pressed; otherwise, false.

◆ command()

bool xtd::forms::key_event_args::command ( ) const
inline

Gets a value indicating whether the CMD key was pressed.

Returns
true if the CMD key was pressed; otherwise, false.

◆ control()

bool xtd::forms::key_event_args::control ( ) const
inline

Gets a value indicating whether the CTRL key was pressed.

Returns
true if the CTRL key was pressed; otherwise, false.

◆ handled() [1/2]

bool xtd::forms::key_event_args::handled ( ) const
inline

Gets a value indicating whether the event was handled.

Returns
true to bypass the control's default handling; otherwise, false to also pass the event along to the default control handler.
Remarks
handled is implemented differently by different controls within xtd.forms. For controls like text_box which subclass native Win32 controls, it is interpreted to mean that the key message should not be passed to the underlying native control. If you set handled to true on a text_box, that control will not pass the key press events to the underlying Win32 text box control, but it will still display the characters that the user typed.

◆ handled() [2/2]

void xtd::forms::key_event_args::handled ( bool  handled)
inline

Sets a value indicating whether the event was handled.

Parameters
handledtrue to bypass the control's default handling; otherwise, false to also pass the event along to the default control handler.
Remarks
handled is implemented differently by different controls within xtd.forms. For controls like text_box which subclass native Win32 controls, it is interpreted to mean that the key message should not be passed to the underlying native control. If you set handled to true on a text_box, that control will not pass the key press events to the underlying Win32 text box control, but it will still display the characters that the user typed.

◆ key_code()

keys xtd::forms::key_event_args::key_code ( ) const
inline

Gets the keyboard code for a key_down or key_up event.

Returns
A xtd::forms::keys value that is the key code for the event.

◆ key_data()

keys xtd::forms::key_event_args::key_data ( ) const
inline

Gets the key data for a key_down or key_up event.

Returns
A xtd::forms::keys representing the key code for the key that was pressed, combined with modifier flags that indicate which combination of CMD, CTRL, SHIFT, and ALT keys was pressed at the same time.
Remarks
You can use constants from Keys to extract information from the key_data property. Use the bitwise AND operator to compare data returned by key_data with constants in Keys to obtain information about which keys the user pressed. To determine whether a specific modifier key was pressed, use the command, control, shift, and alt properties.

◆ key_value()

int xtd::forms::key_event_args::key_value ( ) const
inline

Gets the keyboard value for a key_down or key_up event.

Returns
The integer representation of the key_code property.

◆ modifiers()

keys xtd::forms::key_event_args::modifiers ( ) const
inline

Gets the modifier flags for a key_down or key_up event. The flags indicate which combination of CMD, CTRL, SHIFT, and ALT keys was pressed.

Returns
A xtd::forms::keys value representing one or more modifier flags.

◆ shift()

bool xtd::forms::key_event_args::shift ( ) const
inline

Gets a value indicating whether the SHIFT key was pressed.

Returns
true if the SHIFT key was pressed; otherwise, false.

◆ suppress_key_press() [1/2]

bool xtd::forms::key_event_args::suppress_key_press ( ) const
inline

Gets a value indicating whether the key event should be passed on to the underlying control.

Returns
true if the key event should not be sent to the control; otherwise, false.
Remarks
You can assign true to this property in an event handler such as key_down in order to prevent user input.
Setting suppress_key_press to true also sets handled to true.

◆ suppress_key_press() [2/2]

void xtd::forms::key_event_args::suppress_key_press ( bool  suppress_key_press)
inline

Sets a value indicating whether the key event should be passed on to the underlying control.

Parameters
suppress_key_presstrue if the key event should not be sent to the control; otherwise, false.
Remarks
You can assign true to this property in an event handler such as key_down in order to prevent user input.
Setting suppress_key_press to true also sets handled to true.

The documentation for this class was generated from the following file: