TGUI  0.8.8
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 <SFML/Window/Event.hpp>
33 #include <SFML/Window/Keyboard.hpp>
34 
36 
37 namespace tgui
38 {
39  namespace keyboard
40  {
42 
43  inline bool isShiftPressed()
44  {
45  return sf::Keyboard::isKeyPressed(sf::Keyboard::LShift) || sf::Keyboard::isKeyPressed(sf::Keyboard::RShift);
46  }
47 
49 
50  inline bool isMultiselectModifierPressed()
51  {
52 #ifdef TGUI_SYSTEM_MACOS
53  return sf::Keyboard::isKeyPressed(sf::Keyboard::LSystem) || sf::Keyboard::isKeyPressed(sf::Keyboard::RSystem);
54 #else
55  return sf::Keyboard::isKeyPressed(sf::Keyboard::LControl) || sf::Keyboard::isKeyPressed(sf::Keyboard::RControl);
56 #endif
57  }
58 
60 
61  inline bool isKeyPressCopy(const sf::Event::KeyEvent& event)
62  {
63 #ifdef TGUI_SYSTEM_MACOS
64  return (event.code == sf::Keyboard::Key::C) && !event.control && !event.alt && !event.shift && event.system;
65 #else
66  return (event.code == sf::Keyboard::Key::C) && event.control && !event.alt && !event.shift && !event.system;
67 #endif
68  }
69 
71 
72  inline bool isKeyPressCut(const sf::Event::KeyEvent& event)
73  {
74 #ifdef TGUI_SYSTEM_MACOS
75  return (event.code == sf::Keyboard::Key::X) && !event.control && !event.alt && !event.shift && event.system;
76 #else
77  return (event.code == sf::Keyboard::Key::X) && event.control && !event.alt && !event.shift && !event.system;
78 #endif
79  }
80 
82 
83  inline bool isKeyPressPaste(const sf::Event::KeyEvent& event)
84  {
85 #ifdef TGUI_SYSTEM_MACOS
86  return (event.code == sf::Keyboard::Key::V) && !event.control && !event.alt && !event.shift && event.system;
87 #else
88  return (event.code == sf::Keyboard::Key::V) && event.control && !event.alt && !event.shift && !event.system;
89 #endif
90  }
91 
93 
94  inline bool isKeyPressSelectAll(const sf::Event::KeyEvent& event)
95  {
96 #ifdef TGUI_SYSTEM_MACOS
97  return (event.code == sf::Keyboard::Key::A) && !event.control && !event.alt && !event.shift && event.system;
98 #else
99  return (event.code == sf::Keyboard::Key::A) && event.control && !event.alt && !event.shift && !event.system;
100 #endif
101  }
102 
104 
105  inline bool isKeyPressMoveCaretLeft(const sf::Event::KeyEvent& event)
106  {
107  return (event.code == sf::Keyboard::Key::Left) && !event.control && !event.alt && !event.system;
108  }
109 
111 
112  inline bool isKeyPressMoveCaretRight(const sf::Event::KeyEvent& event)
113  {
114  return (event.code == sf::Keyboard::Key::Right) && !event.control && !event.alt && !event.system;
115  }
116 
118 
119  inline bool isKeyPressMoveCaretWordBegin(const sf::Event::KeyEvent& event)
120  {
121 #ifdef TGUI_SYSTEM_MACOS
122  return (event.code == sf::Keyboard::Key::Left) && !event.control && event.alt && !event.system;
123 #else
124  return (event.code == sf::Keyboard::Key::Left) && event.control && !event.alt && !event.system;
125 #endif
126  }
127 
129 
130  inline bool isKeyPressMoveCaretWordEnd(const sf::Event::KeyEvent& event)
131  {
132 #ifdef TGUI_SYSTEM_MACOS
133  return (event.code == sf::Keyboard::Key::Right) && !event.control && event.alt && !event.system;
134 #else
135  return (event.code == sf::Keyboard::Key::Right) && event.control && !event.alt && !event.system;
136 #endif
137  }
138 
140 
141  inline bool isKeyPressMoveCaretUp(const sf::Event::KeyEvent& event)
142  {
143 #ifdef TGUI_SYSTEM_MACOS
144  // Option+UpArrow should actually move to the beginning of the paragraph (or the previous one), but we don't support this
145  return (event.code == sf::Keyboard::Key::Up) && !event.control && !event.system;
146 #else
147  return (event.code == sf::Keyboard::Key::Up) && !event.alt && !event.system;
148 #endif
149  }
150 
152 
153  inline bool isKeyPressMoveCaretDown(const sf::Event::KeyEvent& event)
154  {
155 #ifdef TGUI_SYSTEM_MACOS
156  // Option+DownArrow should actually move to the end of the paragraph (or the next one), but we don't support this
157  return (event.code == sf::Keyboard::Key::Down) && !event.control && !event.system;
158 #else
159  return (event.code == sf::Keyboard::Key::Down) && !event.alt && !event.system;
160 #endif
161  }
162 
164 
165  inline bool isKeyPressMoveCaretLineStart(const sf::Event::KeyEvent& event)
166  {
167 #ifdef TGUI_SYSTEM_MACOS
168  if ((event.code == sf::Keyboard::Key::Left) && !event.control && !event.alt && event.system)
169  return true;
170 #endif
171  return (event.code == sf::Keyboard::Key::Home) && !event.control && !event.alt && !event.system;
172  }
173 
175 
176  inline bool isKeyPressMoveCaretLineEnd(const sf::Event::KeyEvent& event)
177  {
178 #ifdef TGUI_SYSTEM_MACOS
179  if ((event.code == sf::Keyboard::Key::Right) && !event.control && !event.alt && event.system)
180  return true;
181 #endif
182  return (event.code == sf::Keyboard::Key::End) && !event.control && !event.alt && !event.system;
183  }
184 
186 
187  inline bool isKeyPressMoveCaretDocumentBegin(const sf::Event::KeyEvent& event)
188  {
189 #ifdef TGUI_SYSTEM_MACOS
190  return ((event.code == sf::Keyboard::Key::Up) && !event.control && !event.alt && event.system)
191  || ((event.code == sf::Keyboard::Key::Home) && !event.control && !event.alt && event.system);
192 #else
193  return (event.code == sf::Keyboard::Key::Home) && event.control && !event.alt && !event.system;
194 #endif
195  }
196 
198 
199  inline bool isKeyPressMoveCaretDocumentEnd(const sf::Event::KeyEvent& event)
200  {
201 #ifdef TGUI_SYSTEM_MACOS
202  return ((event.code == sf::Keyboard::Key::Down) && !event.control && !event.alt && event.system)
203  || ((event.code == sf::Keyboard::Key::End) && !event.control && !event.alt && event.system);
204 #else
205  return (event.code == sf::Keyboard::Key::End) && event.control && !event.alt && !event.system;
206 #endif
207  }
208 
210  }
211 }
212 
214 
215 #endif // TGUI_KEYBOARD_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37