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.
key_event_args.h
Go to the documentation of this file.
1 #pragma once
5 
6 #include <xtd/event_args.h>
7 #include "keys.h"
8 
10 namespace xtd {
12  namespace forms {
22  class key_event_args : public event_args {
23  public:
25 
28  key_event_args() = default;
31  key_event_args(xtd::forms::keys key_data) : key_data_(key_data) {}
33 
36  key_event_args& operator=(const xtd::forms::key_event_args& key_event_args) = default;
38 
40 
44  bool alt() const {return (key_data_ & xtd::forms::keys::alt) == keys::alt;}
45 
48  bool command() const {return (key_data_ & xtd::forms::keys::command) == keys::command;}
49 
52  bool control() const {return (key_data_ & xtd::forms::keys::control) == keys::control;}
53 
57  bool handled() const {return handled_;}
61  void handled(bool handled) {handled_ = handled;}
62 
65  keys key_code() const {return key_data_ & xtd::forms::keys::key_code;}
66 
70  keys key_data() const {return key_data_;}
71 
74  int key_value() const {return static_cast<int>(key_data_) & 0xFFFF;}
75 
78  keys modifiers() const {return key_data_ & xtd::forms::keys::modifiers;}
79 
82  bool shift() const {return (key_data_ & xtd::forms::keys::shift) == keys::shift;}
83 
88  bool suppress_key_press() const {return suppress_key_press_;}
94  suppress_key_press_ = suppress_key_press;
95  if (suppress_key_press) handled(true);
96  }
98 
99  private:
100  xtd::forms::keys key_data_;
101  bool handled_ = false;
102  bool suppress_key_press_ = false;
103  };
104  }
105 }
The bitmask to extract modifiers from a key value.
key_event_args()=default
Initializes a new instance of the key_event_args class.
Contains xtd::event_args event args.
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
keys key_data() const
Gets the key data for a key_down or key_up event.
Definition: key_event_args.h:70
The SHIFt modifier key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
void suppress_key_press(bool suppress_key_press)
Sets a value indicating whether the key event should be passed on to the underlying control...
Definition: key_event_args.h:93
bool handled() const
Gets a value indicating whether the event was handled.
Definition: key_event_args.h:57
keys key_code() const
Gets the keyboard code for a key_down or key_up event.
Definition: key_event_args.h:65
The bitmask to extract a key code from a key value.
int key_value() const
Gets the keyboard value for a key_down or key_up event.
Definition: key_event_args.h:74
void handled(bool handled)
Sets a value indicating whether the event was handled.
Definition: key_event_args.h:61
The CTRL modifier key.
bool alt() const
Gets a value indicating whether the ALT key was pressed.
Definition: key_event_args.h:44
bool shift() const
Gets a value indicating whether the SHIFT key was pressed.
Definition: key_event_args.h:82
The ALT modifier key.
bool command() const
Gets a value indicating whether the CMD key was pressed.
Definition: key_event_args.h:48
keys
Specifies key codes and modifiers.
Definition: keys.h:73
Contains xtd::forms::keys enum class.
key_event_args(xtd::forms::keys key_data)
Initializes a new instance of the key_event_args class.
Definition: key_event_args.h:31
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
Provides data for the key_down or key_up event.
Definition: key_event_args.h:22
The CMD modifier key.
bool suppress_key_press() const
Gets a value indicating whether the key event should be passed on to the underlying control...
Definition: key_event_args.h:88
bool control() const
Gets a value indicating whether the CTRL key was pressed.
Definition: key_event_args.h:52
keys modifiers() const
Gets the modifier flags for a key_down or key_up event. The flags indicate which combination of CMD...
Definition: key_event_args.h:78