xtd 0.2.0
key_event_args.h
Go to the documentation of this file.
1 #pragma once
5 #include "keys.h"
6 #include <xtd/event_args>
7 
9 namespace xtd {
11  namespace forms {
23  class key_event_args : public event_args {
24  public:
26 
29  key_event_args() = default;
32  explicit key_event_args(xtd::forms::keys key_data) : key_data_(key_data) {}
34 
37  key_event_args& operator =(const xtd::forms::key_event_args& key_event_args) = default;
39 
41 
45  bool alt() const noexcept {return (key_data_ & xtd::forms::keys::alt) == keys::alt;}
46 
49  bool command() const noexcept {return (key_data_ & xtd::forms::keys::command) == keys::command;}
50 
53  bool control() const noexcept {return (key_data_ & xtd::forms::keys::control) == keys::control;}
54 
58  bool handled() const noexcept {return handled_;}
62  void handled(bool handled) {handled_ = handled;}
63 
66  keys key_code() const noexcept {return key_data_ & xtd::forms::keys::key_code;}
67 
71  keys key_data() const noexcept {return key_data_;}
72 
75  int32 key_value() const noexcept {return static_cast<int32>(key_data_) & 0xFFFF;}
76 
79  keys modifiers() const noexcept {return key_data_ & xtd::forms::keys::modifiers;}
80 
83  bool shift() const noexcept {return (key_data_ & xtd::forms::keys::shift) == keys::shift;}
84 
89  bool suppress_key_press() const noexcept {return suppress_key_press_;}
95  suppress_key_press_ = suppress_key_press;
96  if (suppress_key_press) handled(true);
97  }
99 
100  private:
102  bool handled_ = false;
103  bool suppress_key_press_ = false;
104  };
105  }
106 }
The bitmask to extract modifiers from a key value.
key_event_args()=default
Initializes a new instance of the key_event_args class.
bool control() const noexcept
Gets a value indicating whether the CTRL key was pressed.
Definition: key_event_args.h:53
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
The SHIFt modifier key.
No key pressed.
bool suppress_key_press() const noexcept
Gets a value indicating whether the key event should be passed on to the underlying control...
Definition: key_event_args.h:89
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:94
int32 key_value() const noexcept
Gets the keyboard value for a xtd::forms::control::key_down or xtd::forms::control::key_up event...
Definition: key_event_args.h:75
The bitmask to extract a key code from a key value.
void handled(bool handled)
Sets a value indicating whether the event was handled.
Definition: key_event_args.h:62
The CTRL modifier key.
The ALT modifier key.
bool command() const noexcept
Gets a value indicating whether the CMD key was pressed.
Definition: key_event_args.h:49
bool alt() const noexcept
Gets a value indicating whether the ALT key was pressed.
Definition: key_event_args.h:45
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
bool shift() const noexcept
Gets a value indicating whether the SHIFT key was pressed.
Definition: key_event_args.h:83
keys
Specifies key codes and modifiers.
Definition: keys.h:74
keys key_code() const noexcept
Gets the keyboard code for a xtd::forms::control::key_down or xtd::forms::control::key_up event...
Definition: key_event_args.h:66
Contains xtd::forms::keys enum class.
bool handled() const noexcept
Gets a value indicating whether the event was handled.
Definition: key_event_args.h:58
keys modifiers() const noexcept
Gets the modifier flags for a xtd::forms::control::key_down or xtd::forms::control::key_up event...
Definition: key_event_args.h:79
key_event_args(xtd::forms::keys key_data)
Initializes a new instance of the key_event_args class.
Definition: key_event_args.h:32
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
keys key_data() const noexcept
Gets the key data for a xtd::forms::control::key_down or xtd::forms::control::key_up event...
Definition: key_event_args.h:71
Provides data for the xtd::forms::control::key_down or xtd::forms::control::key_up event...
Definition: key_event_args.h:23
The CMD modifier key.