| 1847 | } |
| 1848 | |
| 1849 | string keycode_to_name(int keycode, bool shorten) |
| 1850 | { |
| 1851 | // nb both of these use string literal concatenation |
| 1852 | #define CTRL_DESC(x) (shorten ? ("^" x) : ("Ctrl-" x)) |
| 1853 | #define NP_DESC(x) (shorten ? ("NP" x) : ("Numpad " x)) |
| 1854 | |
| 1855 | string prefix = ""; |
| 1856 | |
| 1857 | // ugh |
| 1858 | if (keycode - CK_CMD_BASE < 256) |
| 1859 | { |
| 1860 | // could still also have alt on top of this |
| 1861 | prefix = (shorten ? "Cmd-" : "Command-"); |
| 1862 | keycode -= CK_CMD_BASE; |
| 1863 | } |
| 1864 | |
| 1865 | if (keycode - CK_ALT_BASE >= CK_MIN_INTERNAL && keycode - CK_ALT_BASE <= 256) |
| 1866 | { |
| 1867 | prefix += "Alt-"; |
| 1868 | keycode -= CK_ALT_BASE; |
| 1869 | } |
| 1870 | |
| 1871 | // this is printable, but it's very confusing to try to use ' ' to print it |
| 1872 | // in circumstances where a name is called for |
| 1873 | if (keycode == ' ') |
| 1874 | return prefix + "Space"; |
| 1875 | |
| 1876 | if (keycode_is_printable(keycode)) |
| 1877 | return prefix + string(1, keycode); |
| 1878 | |
| 1879 | // shift/ctrl-modified keys aside from shift-tab don't seem to work on mac |
| 1880 | // console, and are somewhat spotty on webtiles. |
| 1881 | const bool shift = (keycode >= CK_SHIFT_UP && keycode <= CK_SHIFT_PGDN); |
| 1882 | const bool ctrl = (keycode >= CK_CTRL_UP && keycode <= CK_CTRL_PGDN); |
| 1883 | const bool ctrlshift = (keycode >= CK_CTRL_SHIFT_UP && keycode <= CK_CTRL_SHIFT_PGDN); |
| 1884 | |
| 1885 | if (shift) |
| 1886 | { |
| 1887 | keycode -= (CK_SHIFT_UP - CK_UP); |
| 1888 | prefix += "Shift-"; |
| 1889 | } |
| 1890 | else if (ctrl) |
| 1891 | { |
| 1892 | keycode -= (CK_CTRL_UP - CK_UP); |
| 1893 | prefix += CTRL_DESC(""); |
| 1894 | } |
| 1895 | else if (ctrlshift) |
| 1896 | { |
| 1897 | keycode -= (CK_CTRL_SHIFT_UP - CK_UP); |
| 1898 | prefix += CTRL_DESC("Shift-"); |
| 1899 | } |
| 1900 | |
| 1901 | // placeholder |
| 1902 | switch (keycode) |
| 1903 | { |
| 1904 | case 0: return "NULL"; |
| 1905 | case 8: return prefix + "Backspace"; // CK_BKSP |
| 1906 | case 9: return prefix + "Tab"; |
no test coverage detected