MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Samples / map_multichar_key

Function map_multichar_key

framework/platform/unix/direct_window.cpp:162–212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160 KeyCode::Backspace};
161
162static KeyCode map_multichar_key(int tty_fd, KeyCode initial)
163{
164 static std::map<std::string, KeyCode> mc_map; // Static for one-time-init
165 if (mc_map.size() == 0)
166 {
167 mc_map["[A"] = KeyCode::Up;
168 mc_map["[B"] = KeyCode::Down;
169 mc_map["[C"] = KeyCode::Right;
170 mc_map["[D"] = KeyCode::Left;
171 mc_map["[2~"] = KeyCode::Insert;
172 mc_map["[3~"] = KeyCode::DelKey;
173 mc_map["[5~"] = KeyCode::PageUp;
174 mc_map["[6~"] = KeyCode::PageDown;
175 mc_map["[H"] = KeyCode::Home;
176 mc_map["[F"] = KeyCode::End;
177 mc_map["OP"] = KeyCode::F1;
178 mc_map["OQ"] = KeyCode::F2;
179 mc_map["OR"] = KeyCode::F3;
180 mc_map["OS"] = KeyCode::F4;
181 mc_map["[15~"] = KeyCode::F5;
182 mc_map["[17~"] = KeyCode::F6;
183 mc_map["[18~"] = KeyCode::F7;
184 mc_map["[19~"] = KeyCode::F8;
185 mc_map["[20~"] = KeyCode::F9;
186 mc_map["[21~"] = KeyCode::F10;
187 mc_map["[23~"] = KeyCode::F11;
188 mc_map["[24~"] = KeyCode::F12;
189 }
190
191 char key;
192 std::string buf;
193
194 while (::read(tty_fd, &key, 1) == 1)
195 {
196 buf += key;
197 }
198
199 if (buf.size() == 0)
200 {
201 return initial; // Nothing new read, just return the initial char
202 }
203
204 // Is it a code we recognise?
205 auto iter = mc_map.find(buf);
206 if (iter != mc_map.end())
207 {
208 return iter->second;
209 }
210
211 return KeyCode::Unknown;
212}
213
214} // namespace
215DirectWindow::DirectWindow(Platform *platform, const Window::Properties &properties) :

Callers 1

process_eventsMethod · 0.85

Calls 3

readFunction · 0.85
sizeMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected