TGUI  0.9-beta
Keyboard.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2020 Bruno Van de Velde (vdv_b@tgui.eu)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 
26 #ifndef TGUI_KEYBOARD_HPP
27 #define TGUI_KEYBOARD_HPP
28 
30 
31 #include <TGUI/Config.hpp>
32 #include <TGUI/Event.hpp>
33 #include <TGUI/Backend.hpp>
34 
36 
37 namespace tgui
38 {
39  namespace keyboard
40  {
42 
43  inline bool isShiftPressed()
44  {
45  return getBackend()->isKeyboardModifierPressed(Event::KeyModifier::Shift);
46  }
47 
49 
50  inline void openVirtualKeyboard(const FloatRect& inputRect)
51  {
52  getBackend()->openVirtualKeyboard(inputRect);
53  }
54 
56 
57  inline void closeVirtualKeyboard()
58  {
59  getBackend()->closeVirtualKeyboard();
60  }
61 
63 
64  inline bool isMultiselectModifierPressed()
65  {
66 #ifdef TGUI_SYSTEM_MACOS
67  return getBackend()->isKeyboardModifierPressed(Event::KeyModifier::System);
68 #else
69  return getBackend()->isKeyboardModifierPressed(Event::KeyModifier::Control);
70 #endif
71  }
72 
74 
75  inline bool isKeyPressCopy(const Event::KeyEvent& event)
76  {
77 #ifdef TGUI_SYSTEM_MACOS
78  return (event.code == Event::KeyboardKey::C) && !event.control && !event.alt && !event.shift && event.system;
79 #else
80  return (event.code == Event::KeyboardKey::C) && event.control && !event.alt && !event.shift && !event.system;
81 #endif
82  }
83 
85 
86  inline bool isKeyPressCut(const Event::KeyEvent& event)
87  {
88 #ifdef TGUI_SYSTEM_MACOS
89  return (event.code == Event::KeyboardKey::X) && !event.control && !event.alt && !event.shift && event.system;
90 #else
91  return (event.code == Event::KeyboardKey::X) && event.control && !event.alt && !event.shift && !event.system;
92 #endif
93  }
94 
96 
97  inline bool isKeyPressPaste(const Event::KeyEvent& event)
98  {
99 #ifdef TGUI_SYSTEM_MACOS
100  return (event.code == Event::KeyboardKey::V) && !event.control && !event.alt && !event.shift && event.system;
101 #else
102  return (event.code == Event::KeyboardKey::V) && event.control && !event.alt && !event.shift && !event.system;
103 #endif
104  }
105 
107 
108  inline bool isKeyPressSelectAll(const Event::KeyEvent& event)
109  {
110 #ifdef TGUI_SYSTEM_MACOS
111  return (event.code == Event::KeyboardKey::A) && !event.control && !event.alt && !event.shift && event.system;
112 #else
113  return (event.code == Event::KeyboardKey::A) && event.control && !event.alt && !event.shift && !event.system;
114 #endif
115  }
116 
118 
119  inline bool isKeyPressMoveCaretLeft(const Event::KeyEvent& event)
120  {
121  return (event.code == Event::KeyboardKey::Left) && !event.control && !event.alt && !event.system;
122  }
123 
125 
126  inline bool isKeyPressMoveCaretRight(const Event::KeyEvent& event)
127  {
128  return (event.code == Event::KeyboardKey::Right) && !event.control && !event.alt && !event.system;
129  }
130 
132 
133  inline bool isKeyPressMoveCaretWordBegin(const Event::KeyEvent& event)
134  {
135 #ifdef TGUI_SYSTEM_MACOS
136  return (event.code == Event::KeyboardKey::Left) && !event.control && event.alt && !event.system;
137 #else
138  return (event.code == Event::KeyboardKey::Left) && event.control && !event.alt && !event.system;
139 #endif
140  }
141 
143 
144  inline bool isKeyPressMoveCaretWordEnd(const Event::KeyEvent& event)
145  {
146 #ifdef TGUI_SYSTEM_MACOS
147  return (event.code == Event::KeyboardKey::Right) && !event.control && event.alt && !event.system;
148 #else
149  return (event.code == Event::KeyboardKey::Right) && event.control && !event.alt && !event.system;
150 #endif
151  }
152 
154 
155  inline bool isKeyPressMoveCaretUp(const Event::KeyEvent& event)
156  {
157 #ifdef TGUI_SYSTEM_MACOS
158  // Option+UpArrow should actually move to the beginning of the paragraph (or the previous one), but we don't support this
159  return (event.code == Event::KeyboardKey::Up) && !event.control && !event.system;
160 #else
161  return (event.code == Event::KeyboardKey::Up) && !event.alt && !event.system;
162 #endif
163  }
164 
166 
167  inline bool isKeyPressMoveCaretDown(const Event::KeyEvent& event)
168  {
169 #ifdef TGUI_SYSTEM_MACOS
170  // Option+DownArrow should actually move to the end of the paragraph (or the next one), but we don't support this
171  return (event.code == Event::KeyboardKey::Down) && !event.control && !event.system;
172 #else
173  return (event.code == Event::KeyboardKey::Down) && !event.alt && !event.system;
174 #endif
175  }
176 
178 
179  inline bool isKeyPressMoveCaretLineStart(const Event::KeyEvent& event)
180  {
181 #ifdef TGUI_SYSTEM_MACOS
182  if ((event.code == Event::KeyboardKey::Left) && !event.control && !event.alt && event.system)
183  return true;
184 #endif
185  return (event.code == Event::KeyboardKey::Home) && !event.control && !event.alt && !event.system;
186  }
187 
189 
190  inline bool isKeyPressMoveCaretLineEnd(const Event::KeyEvent& event)
191  {
192 #ifdef TGUI_SYSTEM_MACOS
193  if ((event.code == Event::KeyboardKey::Right) && !event.control && !event.alt && event.system)
194  return true;
195 #endif
196  return (event.code == Event::KeyboardKey::End) && !event.control && !event.alt && !event.system;
197  }
198 
200 
201  inline bool isKeyPressMoveCaretDocumentBegin(const Event::KeyEvent& event)
202  {
203 #ifdef TGUI_SYSTEM_MACOS
204  return ((event.code == Event::KeyboardKey::Up) && !event.control && !event.alt && event.system)
205  || ((event.code == Event::KeyboardKey::Home) && !event.control && !event.alt && event.system);
206 #else
207  return (event.code == Event::KeyboardKey::Home) && event.control && !event.alt && !event.system;
208 #endif
209  }
210 
212 
213  inline bool isKeyPressMoveCaretDocumentEnd(const Event::KeyEvent& event)
214  {
215 #ifdef TGUI_SYSTEM_MACOS
216  return ((event.code == Event::KeyboardKey::Down) && !event.control && !event.alt && event.system)
217  || ((event.code == Event::KeyboardKey::End) && !event.control && !event.alt && event.system);
218 #else
219  return (event.code == Event::KeyboardKey::End) && event.control && !event.alt && !event.system;
220 #endif
221  }
222 
224  }
225 }
226 
228 
229 #endif // TGUI_KEYBOARD_HPP
230 
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
TGUI_API std::shared_ptr< BackendBase > getBackend()
Returns the global backend.