Audacity  2.2.2
Functions
Keyboard.cpp File Reference
#include "../Audacity.h"
#include "Keyboard.h"

Go to the source code of this file.

Functions

wxString KeyStringNormalize (const wxString &key)
 
wxString KeyStringDisplay (const wxString &key, bool usesSpecialChars)
 
wxString KeyEventToKeyString (const wxKeyEvent &event)
 

Function Documentation

wxString KeyEventToKeyString ( const wxKeyEvent &  event)

Definition at line 78 of file Keyboard.cpp.

References KeyStringNormalize().

Referenced by CommandManager::FilterKeyEvent(), KeyConfigPrefs::OnFilterKeyDown(), and KeyConfigPrefs::OnHotkeyKeyDown().

79 {
80  wxString newStr = wxT("");
81 
82  long key = event.GetKeyCode();
83 
84  if (event.ControlDown())
85  newStr += wxT("Ctrl+");
86 
87  if (event.AltDown())
88  newStr += wxT("Alt+");
89 
90  if (event.ShiftDown())
91  newStr += wxT("Shift+");
92 
93 #if defined(__WXMAC__)
94  if (event.RawControlDown())
95  newStr += wxT("RawCtrl+");
96 #endif
97 
98  if (event.RawControlDown() && key >= 1 && key <= 26)
99  newStr += (wxChar)(64 + key);
100  else if (key >= 33 && key <= 255 && key != 127)
101  newStr += (wxChar)key;
102  else
103  {
104  switch(key)
105  {
106  case WXK_BACK:
107  newStr += wxT("Backspace");
108  break;
109  case WXK_DELETE:
110  newStr += wxT("Delete");
111  break;
112  case WXK_SPACE:
113  newStr += wxT("Space");
114  break;
115  case WXK_TAB:
116  newStr += wxT("Tab");
117  break;
118  case WXK_RETURN:
119  newStr += wxT("Return");
120  break;
121  case WXK_PAGEUP:
122  newStr += wxT("PageUp");
123  break;
124  case WXK_PAGEDOWN:
125  newStr += wxT("PageDown");
126  break;
127  case WXK_END:
128  newStr += wxT("End");
129  break;
130  case WXK_HOME:
131  newStr += wxT("Home");
132  break;
133  case WXK_LEFT:
134  newStr += wxT("Left");
135  break;
136  case WXK_UP:
137  newStr += wxT("Up");
138  break;
139  case WXK_RIGHT:
140  newStr += wxT("Right");
141  break;
142  case WXK_DOWN:
143  newStr += wxT("Down");
144  break;
145  case WXK_ESCAPE:
146  newStr += wxT("Escape");
147  break;
148  case WXK_INSERT:
149  newStr += wxT("Insert");
150  break;
151  case WXK_NUMPAD0:
152  newStr += wxT("NUMPAD0");
153  break;
154  case WXK_NUMPAD1:
155  newStr += wxT("NUMPAD1");
156  break;
157  case WXK_NUMPAD2:
158  newStr += wxT("NUMPAD2");
159  break;
160  case WXK_NUMPAD3:
161  newStr += wxT("NUMPAD3");
162  break;
163  case WXK_NUMPAD4:
164  newStr += wxT("NUMPAD4");
165  break;
166  case WXK_NUMPAD5:
167  newStr += wxT("NUMPAD5");
168  break;
169  case WXK_NUMPAD6:
170  newStr += wxT("NUMPAD6");
171  break;
172  case WXK_NUMPAD7:
173  newStr += wxT("NUMPAD7");
174  break;
175  case WXK_NUMPAD8:
176  newStr += wxT("NUMPAD8");
177  break;
178  case WXK_NUMPAD9:
179  newStr += wxT("NUMPAD9");
180  break;
181  case WXK_MULTIPLY:
182  newStr += wxT("*");
183  break;
184  case WXK_ADD:
185  newStr += wxT("+");
186  break;
187  case WXK_SUBTRACT:
188  newStr += wxT("-");
189  break;
190  case WXK_DECIMAL:
191  newStr += wxT(".");
192  break;
193  case WXK_DIVIDE:
194  newStr += wxT("/");
195  break;
196  case WXK_F1:
197  newStr += wxT("F1");
198  break;
199  case WXK_F2:
200  newStr += wxT("F2");
201  break;
202  case WXK_F3:
203  newStr += wxT("F3");
204  break;
205  case WXK_F4:
206  newStr += wxT("F4");
207  break;
208  case WXK_F5:
209  newStr += wxT("F5");
210  break;
211  case WXK_F6:
212  newStr += wxT("F6");
213  break;
214  case WXK_F7:
215  newStr += wxT("F7");
216  break;
217  case WXK_F8:
218  newStr += wxT("F8");
219  break;
220  case WXK_F9:
221  newStr += wxT("F9");
222  break;
223  case WXK_F10:
224  newStr += wxT("F10");
225  break;
226  case WXK_F11:
227  newStr += wxT("F11");
228  break;
229  case WXK_F12:
230  newStr += wxT("F12");
231  break;
232  case WXK_F13:
233  newStr += wxT("F13");
234  break;
235  case WXK_F14:
236  newStr += wxT("F14");
237  break;
238  case WXK_F15:
239  newStr += wxT("F15");
240  break;
241  case WXK_F16:
242  newStr += wxT("F16");
243  break;
244  case WXK_F17:
245  newStr += wxT("F17");
246  break;
247  case WXK_F18:
248  newStr += wxT("F18");
249  break;
250  case WXK_F19:
251  newStr += wxT("F19");
252  break;
253  case WXK_F20:
254  newStr += wxT("F20");
255  break;
256  case WXK_F21:
257  newStr += wxT("F21");
258  break;
259  case WXK_F22:
260  newStr += wxT("F22");
261  break;
262  case WXK_F23:
263  newStr += wxT("F23");
264  break;
265  case WXK_F24:
266  newStr += wxT("F24");
267  break;
268  case WXK_NUMPAD_ENTER:
269  newStr += wxT("NUMPAD_ENTER");
270  break;
271  case WXK_NUMPAD_F1:
272  newStr += wxT("NUMPAD_F1");
273  break;
274  case WXK_NUMPAD_F2:
275  newStr += wxT("NUMPAD_F2");
276  break;
277  case WXK_NUMPAD_F3:
278  newStr += wxT("NUMPAD_F3");
279  break;
280  case WXK_NUMPAD_F4:
281  newStr += wxT("NUMPAD_F4");
282  break;
283  case WXK_NUMPAD_HOME:
284  newStr += wxT("NUMPAD_HOME");
285  break;
286  case WXK_NUMPAD_LEFT:
287  newStr += wxT("NUMPAD_LEFT");
288  break;
289  case WXK_NUMPAD_UP:
290  newStr += wxT("NUMPAD_UP");
291  break;
292  case WXK_NUMPAD_RIGHT:
293  newStr += wxT("NUMPAD_RIGHT");
294  break;
295  case WXK_NUMPAD_DOWN:
296  newStr += wxT("NUMPAD_DOWN");
297  break;
298  case WXK_NUMPAD_PAGEUP:
299  newStr += wxT("NUMPAD_PAGEUP");
300  break;
301  case WXK_NUMPAD_PAGEDOWN:
302  newStr += wxT("NUMPAD_PAGEDOWN");
303  break;
304  case WXK_NUMPAD_END:
305  newStr += wxT("NUMPAD_END");
306  break;
307  case WXK_NUMPAD_BEGIN:
308  newStr += wxT("NUMPAD_HOME");
309  break;
310  case WXK_NUMPAD_INSERT:
311  newStr += wxT("NUMPAD_INSERT");
312  break;
313  case WXK_NUMPAD_DELETE:
314  newStr += wxT("NUMPAD_DELETE");
315  break;
316  case WXK_NUMPAD_EQUAL:
317  newStr += wxT("NUMPAD_EQUAL");
318  break;
319  case WXK_NUMPAD_MULTIPLY:
320  newStr += wxT("NUMPAD_MULTIPLY");
321  break;
322  case WXK_NUMPAD_ADD:
323  newStr += wxT("NUMPAD_ADD");
324  break;
325  case WXK_NUMPAD_SUBTRACT:
326  newStr += wxT("NUMPAD_SUBTRACT");
327  break;
328  case WXK_NUMPAD_DECIMAL:
329  newStr += wxT("NUMPAD_DECIMAL");
330  break;
331  case WXK_NUMPAD_DIVIDE:
332  newStr += wxT("NUMPAD_DIVIDE");
333  break;
334  default:
335  return wxT(""); // Don't do anything if we don't recognize the key
336  }
337  }
338 
339  return KeyStringNormalize(newStr);
340 }
wxString KeyStringNormalize(const wxString &key)
Definition: Keyboard.cpp:16
wxString KeyStringDisplay ( const wxString &  key,
bool  usesSpecialChars 
)

Definition at line 53 of file Keyboard.cpp.

References KeyStringNormalize().

Referenced by CommandManager::DescribeCommandsAndShortcuts(), KeyConfigPrefs::OnFilterKeyDown(), KeyConfigPrefs::OnHotkeyKeyDown(), SelectHandle::Preview(), and KeyView::RefreshBindings().

54 {
55  (void)usesSpecialChars;//compiler food
56  wxString newkey = KeyStringNormalize(key);
57 #if defined(__WXMAC__)
58 
59  if (!usesSpecialChars) {
60  // Compose user-visible keystroke names, all ASCII
61  newkey.Replace(wxT("RawCtrl+"), wxT("Control+"));
62  newkey.Replace(wxT("Alt+"), wxT("Option+"));
63  newkey.Replace(wxT("Ctrl+"), wxT("Command+"));
64  }
65  else {
66  // Compose user-visible keystroke names, with special characters
67  newkey.Replace(wxT("Shift+"), wxT("\u21e7"));
68  newkey.Replace(wxT("RawCtrl+"), '^');
69  newkey.Replace(wxT("Alt+"), wxT("\u2325"));
70  newkey.Replace(wxT("Ctrl+"), wxT("\u2318"));
71  }
72 
73 #endif
74 
75  return newkey;
76 }
wxString KeyStringNormalize(const wxString &key)
Definition: Keyboard.cpp:16
wxString KeyStringNormalize ( const wxString &  key)

Definition at line 16 of file Keyboard.cpp.

Referenced by KeyConfigPrefs::Commit(), KeyConfigPrefs::FilterKeys(), CommandManager::HandleXMLTag(), KeyEventToKeyString(), KeyStringDisplay(), CommandManager::NewIdentifier(), CommandManager::SetKeyFromIndex(), CommandManager::SetKeyFromName(), and CommandManager::SetMaxList().

17 {
18 #if defined(__WXMAC__)
19  wxString newkey;
20  wxString temp = key;
21 
22  // PRL: This is needed to parse older preference files.
23  temp.Replace(wxT("XCtrl+"), wxT("Control+"));
24 
25  // PRL: RawCtrl is the proper replacement for Control, when formatting
26  // wxMenuItem, so that wxWidgets shows ^ in the menu. It is written into
27  // NEW preference files (2.2.0 and later).
28  temp.Replace(wxT("RawCtrl+"), wxT("Control+"));
29  temp.Replace(wxT("Ctrl+"), wxT("Command+"));
30 
31  if (temp.Contains(wxT("Control+"))) {
32  newkey += wxT("RawCtrl+");
33  }
34 
35  if (temp.Contains(wxT("Alt+")) || temp.Contains(wxT("Option+"))) {
36  newkey += wxT("Alt+");
37  }
38 
39  if (temp.Contains(wxT("Shift+"))) {
40  newkey += wxT("Shift+");
41  }
42 
43  if (temp.Contains(wxT("Command+"))) {
44  newkey += wxT("Ctrl+");
45  }
46 
47  return newkey + temp.AfterLast(wxT('+'));
48 #else
49  return key;
50 #endif
51 }