MCPcopy Create free account
hub / github.com/NetHack/NetHack / keyValue

Function keyValue

win/Qt/qt_key.cpp:19–41  ·  view source on GitHub ↗

convert a Qt key event into a simple ASCII character

Source from the content-addressed store, hash-verified

17
18// convert a Qt key event into a simple ASCII character
19uchar 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
43NetHackQtKeyBuffer::NetHackQtKeyBuffer() :
44 in(0), out(0)

Callers 3

keyPressEventMethod · 0.85
keyPressEventMethod · 0.85
keyPressEventMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected