Point Cloud Library (PCL)  1.7.0
keyboard_event.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  */
38 
39 #ifndef PCL_VISUALIZATION_KEYBOARD_EVENT_H_
40 #define PCL_VISUALIZATION_KEYBOARD_EVENT_H_
41 
42 #include <string>
43 
44 namespace pcl
45 {
46  namespace visualization
47  {
48  /** /brief Class representing key hit/release events */
50  {
51  public:
52  /** \brief bit patter for the ALT key*/
53  static const unsigned int Alt = 1;
54  /** \brief bit patter for the Control key*/
55  static const unsigned int Ctrl = 2;
56  /** \brief bit patter for the Shift key*/
57  static const unsigned int Shift = 4;
58 
59  /** \brief Constructor
60  * \param[in] action true for key was pressed, false for released
61  * \param[in] key_sym the key-name that caused the action
62  * \param[in] key the key code that caused the action
63  * \param[in] alt whether the alt key was pressed at the time where this event was triggered
64  * \param[in] ctrl whether the ctrl was pressed at the time where this event was triggered
65  * \param[in] shift whether the shift was pressed at the time where this event was triggered
66  */
67  inline KeyboardEvent (bool action, const std::string& key_sym, unsigned char key,
68  bool alt, bool ctrl, bool shift);
69 
70  /**
71  * \return whether the alt key was pressed at the time where this event was triggered
72  */
73  inline bool
74  isAltPressed () const;
75 
76  /**
77  * \return whether the ctrl was pressed at the time where this event was triggered
78  */
79  inline bool
80  isCtrlPressed () const;
81 
82  /**
83  * \return whether the shift was pressed at the time where this event was triggered
84  */
85  inline bool
86  isShiftPressed () const;
87 
88  /**
89  * \return the ASCII Code of the key that caused the event. If 0, then it was a special key, like ALT, F1, F2,... PgUp etc. Then the name of the key is in the keysym field.
90  */
91  inline unsigned char
92  getKeyCode () const;
93 
94  /**
95  * \return name of the key that caused the event
96  */
97  inline const std::string&
98  getKeySym () const;
99 
100  /**
101  * \return true if a key-press caused the event, false otherwise
102  */
103  inline bool
104  keyDown () const;
105 
106  /**
107  * \return true if a key-release caused the event, false otherwise
108  */
109  inline bool
110  keyUp () const;
111 
112  protected:
113 
114  bool action_;
115  unsigned int modifiers_;
116  unsigned char key_code_;
117  std::string key_sym_;
118  };
119 
120  KeyboardEvent::KeyboardEvent (bool action, const std::string& key_sym, unsigned char key,
121  bool alt, bool ctrl, bool shift)
122  : action_ (action)
123  , modifiers_ (0)
124  , key_code_(key)
125  , key_sym_ (key_sym)
126  {
127  if (alt)
128  modifiers_ = Alt;
129 
130  if (ctrl)
131  modifiers_ |= Ctrl;
132 
133  if (shift)
134  modifiers_ |= Shift;
135  }
136 
137  bool
139  {
140  return (modifiers_ & Alt) != 0;
141  }
142 
143  bool
145  {
146  return (modifiers_ & Ctrl) != 0;
147  }
148 
149  bool
151  {
152  return (modifiers_ & Shift) != 0;
153  }
154 
155  unsigned char
157  {
158  return (key_code_);
159  }
160 
161  const std::string&
163  {
164  return (key_sym_);
165  }
166 
167  bool
169  {
170  return (action_);
171  }
172 
173  bool
175  {
176  return (!action_);
177  }
178  } // namespace visualization
179 } // namespace pcl
180 
181 #endif /* PCL_VISUALIZATION_KEYBOARD_EVENT_H_ */
182 
unsigned char getKeyCode() const
KeyboardEvent(bool action, const std::string &key_sym, unsigned char key, bool alt, bool ctrl, bool shift)
Constructor.
static const unsigned int Shift
bit patter for the Shift key
const std::string & getKeySym() const
static const unsigned int Ctrl
bit patter for the Control key
static const unsigned int Alt
bit patter for the ALT key
/brief Class representing key hit/release events