convert a Qt key event into a simple ASCII character
| 17 | |
| 18 | // convert a Qt key event into a simple ASCII character |
| 19 | uchar keyValue(QKeyEvent *key_event) |
| 20 | { |
| 21 | // key_event manipulation derived from NetHackQtBind::notify(); |
| 22 | // used for menus and text windows in qt_menu.cpp, also for |
| 23 | // extended commands in xcmd.cpp and popup yn_function in qt_yndlg.cpp |
| 24 | |
| 25 | const int k = key_event->key(); |
| 26 | Qt::KeyboardModifiers mod = key_event->modifiers(); |
| 27 | const QString &txt = key_event->text(); |
| 28 | QChar ch = !txt.isEmpty() ? txt.at(0) : QChar(0); |
| 29 | |
| 30 | if (ch >= QChar(128)) |
| 31 | ch = QChar(0); |
| 32 | // on OSX, ascii control codes are not sent, force them |
| 33 | if (ch == 0 && (mod & Qt::ControlModifier) != 0) { |
| 34 | if (k >= Qt::Key_A && k <= Qt::Key_Underscore) |
| 35 | ch = QChar((k - (Qt::Key_A - 1))); |
| 36 | } |
| 37 | |
| 38 | uchar result = (uchar) ch.cell(); |
| 39 | //raw_printf("kV: k=%d, ch=%u", k, (unsigned) result); |
| 40 | return result; |
| 41 | } |
| 42 | |
| 43 | NetHackQtKeyBuffer::NetHackQtKeyBuffer() : |
| 44 | in(0), out(0) |
no outgoing calls
no test coverage detected