xtd - Reference Guide  0.1.1
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  key_event_args() = default;
31  key_event_args& operator=(const xtd::forms::key_event_args& key_event_args) = default;
33 
36  bool alt() const {return (key_data_ & xtd::forms::keys::alt) == keys::alt;}
37 
40  bool command() const {return (key_data_ & xtd::forms::keys::command) == keys::command;}
41 
44  bool control() const {return (key_data_ & xtd::forms::keys::control) == keys::control;}
45 
49  bool handled() const {return handled_;}
53  void handled(bool handled) {handled_ = handled;}
54 
57  keys key_code() const {return key_data_ & xtd::forms::keys::key_code;}
58 
62  keys key_data() const {return key_data_;}
63 
66  int key_value() const {return static_cast<int>(key_data_) & 0xFFFF;}
67 
70  keys modifiers() const {return key_data_ & xtd::forms::keys::modifiers;}
71 
74  bool shift() const {return (key_data_ & xtd::forms::keys::shift) == keys::shift;}
75 
80  bool suppress_key_press() const {return suppress_key_press_;}
86  suppress_key_press_ = suppress_key_press;
87  if (suppress_key_press) handled(true);
88  }
89 
90  private:
91  xtd::forms::keys key_data_;
92  bool handled_ = false;
93  bool suppress_key_press_ = false;
94  };
95  }
96 }
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
Provides data for the key_down or key_up event.
Definition: key_event_args.h:22
key_event_args(xtd::forms::keys key_data)
Initializes a new instance of the key_event_args class.
Definition: key_event_args.h:28
bool alt() const
Gets a value indicating whether the ALT key was pressed.
Definition: key_event_args.h:36
keys key_data() const
Gets the key data for a key_down or key_up event.
Definition: key_event_args.h:62
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:70
bool shift() const
Gets a value indicating whether the SHIFT key was pressed.
Definition: key_event_args.h:74
void handled(bool handled)
Sets a value indicating whether the event was handled.
Definition: key_event_args.h:53
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:80
bool control() const
Gets a value indicating whether the CTRL key was pressed.
Definition: key_event_args.h:44
key_event_args()=default
Initializes a new instance of the key_event_args class.
int key_value() const
Gets the keyboard value for a key_down or key_up event.
Definition: key_event_args.h:66
bool handled() const
Gets a value indicating whether the event was handled.
Definition: key_event_args.h:49
keys key_code() const
Gets the keyboard code for a key_down or key_up event.
Definition: key_event_args.h:57
bool command() const
Gets a value indicating whether the CMD key was pressed.
Definition: key_event_args.h:40
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:85
Contains xtd::event_args event args.
keys
Specifies key codes and modifiers.
Definition: keys.h:73
@ command
The CMD modifier key.
@ shift
The SHIFt modifier key.
@ alt
The ALT modifier key.
@ key_code
The bitmask to extract a key code from a key value.
@ modifiers
The bitmask to extract modifiers from a key value.
@ control
The CTRL modifier key.
Contains xtd::forms::keys enum class.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17