Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
keyboard_event.h
Go to the documentation of this file.
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  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * Author: Suat Gedikli (gedikli@willowgarage.com)
37  *
38  */
39 
40 #ifndef PCL_VISUALIZATION_KEYBOARD_EVENT_H_
41 #define PCL_VISUALIZATION_KEYBOARD_EVENT_H_
42 #include <string>
43 
44 namespace pcl
45 {
46  namespace visualization
47  {
50  {
51  public:
53  static const unsigned int Alt = 1;
55  static const unsigned int Ctrl = 2;
57  static const unsigned int Shift = 4;
58 
67  inline KeyboardEvent (bool action, const std::string& key_sym, unsigned char key,
68  bool alt, bool ctrl, bool shift);
69 
73  inline bool
74  isAltPressed () const;
75 
79  inline bool
80  isCtrlPressed () const;
81 
85  inline bool
86  isShiftPressed () const;
87 
91  inline unsigned char
92  getKeyCode () const;
93 
97  inline const std::string&
98  getKeySym () const;
99 
103  inline bool
104  keyDown () const;
105 
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