String keyIdentifierForEvasKeyName(const String& keyName) { if (keyMap().isEmpty()) createKeyMap(); if (keyMap().contains(keyName)) return keyMap().get(keyName); return keyName; }
// loads json array of strings, outs is optional void keyLoad(const char *array, int *outs, unsigned long at) { unsigned short *index; unsigned int i; unsigned int oi=1; if (!array || !*array) { return; } index = (unsigned short*)malloc(strlen(array)); if (!index) { outs[0] = 0; return; } j0g((char*)array, index, strlen(array)); for (i=0; index[i]; i+=2) { int k = keyMap(j0g_safe(i, (char*)array, index), at); if (outs) { outs[oi++] = k; } } if (outs) { outs[0] = oi-1; } free(index); }
static inline void addCharactersToKeyMap(const char from, const char to) { for (char c = from; c <= to; c++) { StringBuilder builder; builder.appendLiteral("U+"); appendUnsignedAsHexFixedSize(c, builder, 4, WTF::Uppercase); keyMap().set(String(&c, 1), builder.toString()); } }
// adds the most recent key press to the key_queue void getKeyPress(void){ int row; int col; int key; row = getRow(); // get the row of current key being pressed col = getCol(row); // get the col of current key being pressed key = keyMap(row,col); // will hold the key value to be added to queue pushKey(key); // push key onto queue }
void keyInit() { memset(keytable, 0, sizeof(keytable)); memset(keytableTmp, 0, sizeof(keytableTmp)); keyMap("OVERFLOW", 0); // becomes 0, error keyLoad(KEYS_BUNDLE, 0, 0); }
void QWSSL5000KeyboardHandler::doKey(uchar code) { int keyCode = Qt::Key_unknown; bool release = false; if (code & 0x80) { release = true; code &= 0x7f; } if (fn && !meta && (code >= 0x42 && code <= 0x52)) { ushort unicode=0; int scan=0; if (code == 0x42) { unicode='X'-'@'; scan=Qt::Key_X; } // Cut else if (code == 0x43) { unicode='C'-'@'; scan=Qt::Key_C; } // Copy else if (code == 0x44) { unicode='V'-'@'; scan=Qt::Key_V; } // Paste else if (code == 0x52) { unicode='Z'-'@'; scan=Qt::Key_Z; } // Undo if (scan) { processKeyEvent(unicode, scan, Qt::ControlModifier, !release, false); return; } } if (code < keyMSize) { keyCode = keyMap()[code].key_code; } bool repeatable = true; if (release && (keyCode == Qt::Key_F34 || keyCode == Qt::Key_F35)) return; // no release for power and light keys if (keyCode >= Qt::Key_F1 && keyCode <= Qt::Key_F35 || keyCode == Qt::Key_Escape || keyCode == Qt::Key_Home || keyCode == Qt::Key_Shift || keyCode == Qt::Key_Meta) repeatable = false; if (qt_screen->isTransformed() && keyCode >= Qt::Key_Left && keyCode <= Qt::Key_Down) { keyCode = transformDirKey(keyCode); } // Ctrl-Alt-Delete exits qws if (ctrl && alt && keyCode == Qt::Key_Delete) { qApp->quit(); } if (keyCode == Qt::Key_F22) { /* Fn key */ fn = !release; } else if (keyCode == Qt::Key_NumLock) { if (release) numLock = !numLock; } else if (keyCode == Qt::AltModifier) { alt = !release; } else if (keyCode == Qt::ControlModifier) { ctrl = !release; } else if (keyCode == Qt::ShiftModifier) { shift = !release; } else if (keyCode == Qt::MetaModifier) { meta = !release; } else if (keyCode == Qt::Key_CapsLock && release) { caps = !caps; } if (keyCode != Qt::Key_unknown) { bool bAlt = alt; bool bCtrl = ctrl; bool bShift = shift; int unicode = 0; if (code < keyMSize) { bool bCaps = caps ^ shift; if (fn) { if (shift) { bCaps = bShift = false; bCtrl = true; } if (meta) { bCaps = bShift = true; bAlt = true; } } else if (meta) { bCaps = bShift = true; } if (code > 40 && caps) { // fn-keys should only react to shift, not caps bCaps = bShift = shift; } if (numLock) { if (keyCode != Qt::Key_Space && keyCode != Qt::Key_Tab) bCaps = bShift = false; } if (keyCode == Qt::Key_Delete && (bAlt || bCtrl)) { keyCode = Qt::Key_BraceLeft; unicode = '['; bCaps = bShift = bAlt = bCtrl = false; } else if (keyCode == Qt::Key_F31 && bCtrl) { keyCode = Qt::Key_QuoteLeft; unicode = '`'; } else if (bCtrl) unicode = keyMap()[code].ctrl_unicode ? keyMap()[code].ctrl_unicode : 0xffff; else if (bCaps) unicode = keyMap()[code].shift_unicode ? keyMap()[code].shift_unicode : 0xffff; else unicode = keyMap()[code].unicode ? keyMap()[code].unicode : 0xffff; } modifiers = 0; if (bAlt) modifiers |= Qt::AltModifier; if (bCtrl) modifiers |= Qt::ControlModifier; if (bShift) modifiers |= Qt::ShiftModifier; // looks wrong -- WWA bool repeat = false; if (prevuni == unicode && prevkey == keyCode && !release) repeat = true; processKeyEvent(unicode, keyCode, modifiers, !release, repeat); if (!release) { prevuni = unicode; prevkey = keyCode; } else { prevkey = prevuni = 0; } } if (repeatable && !release) beginAutoRepeat(prevuni, prevkey, modifiers); else endAutoRepeat(); }
void QWSPC101KeyboardHandler::doKey(uchar code) { int keyCode = Qt::Key_unknown; bool release = false; int keypad = 0; bool softwareRepeat = false; #ifndef QT_QWS_USE_KEYCODES // extended? if (code == 224 #if defined(QT_QWS_IPAQ) && !ipaq_return_pressed #endif ) { extended = 1; return; } else if (code == 225) { extended = 2; return; } #endif if (code & 0x80) { release = true; code &= 0x7f; } #ifndef QT_QWS_USE_KEYCODES if (extended == 1) { switch (code) { case 72: keyCode = Qt::Key_Up; break; case 75: keyCode = Qt::Key_Left; break; case 77: keyCode = Qt::Key_Right; break; case 80: keyCode = Qt::Key_Down; break; case 82: keyCode = Qt::Key_Insert; break; case 71: keyCode = Qt::Key_Home; break; case 73: keyCode = Qt::Key_PageUp; break; case 83: keyCode = Qt::Key_Delete; break; case 79: keyCode = Qt::Key_End; break; case 81: keyCode = Qt::Key_PageDown; break; case 28: keyCode = Qt::Key_Enter; break; case 53: keyCode = Qt::Key_Slash; break; case 0x1d: keyCode = Qt::Key_Control; break; case 0x2a: keyCode = Qt::Key_Print; break; case 0x38: keyCode = Qt::Key_Alt; break; case 0x5b: keyCode = Qt::Key_Super_L; break; case 0x5c: keyCode = Qt::Key_Super_R; break; case 0x5d: keyCode = Qt::Key_Menu; break; #if 0 default: qDebug("extended1 code %x release %d", code, release); break; #endif } } else if (extended == 2) { switch (code) { case 0x1d: return; case 0x45: keyCode = Qt::Key_Pause; break; } } else #endif { if (code < keyMSize) { keyCode = pc101KeyM[code].key_code; } #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) softwareRepeat = true; switch (code) { case 0x7a: case 0x7b: case 0x7c: case 0x7d: keyCode = code - 0x7a + Qt::Key_F9; softwareRepeat = false; break; case 0x79: keyCode = Qt::Key_SysReq; softwareRepeat = false; break; case 0x78: # ifdef QT_QWS_IPAQ keyCode = Qt::Key_F24; // record # else keyCode = Qt::Key_Escape; # endif softwareRepeat = false; break; case 0x60: keyCode = Qt::Key_Return; # ifdef QT_QWS_IPAQ ipaq_return_pressed = !release; # endif break; case 0x67: keyCode = Qt::Key_Right; break; case 0x69: keyCode = Qt::Key_Up; break; case 0x6a: keyCode = Qt::Key_Down; break; case 0x6c: keyCode = Qt::Key_Left; break; } if (qt_screen->isTransformed() && keyCode >= Qt::Key_Left && keyCode <= Qt::Key_Down) { keyCode = transformDirKey(keyCode); } #endif /* Translate shift+Qt::Key_Tab to Qt::Key_Backtab */ if ((keyCode == Qt::Key_Tab) && shift) keyCode = Qt::Key_Backtab; } #ifndef QT_QWS_USE_KEYCODES /* Qt::Keypad consists of extended keys 53 and 28, and non-extended keys 55 and 71 through 83. */ if ((extended == 1) ? (code == 53 || code == 28) : (code == 55 || (code >= 71 && code <= 83))) #else if (code == 55 || code >= 71 && code <= 83 || code == 96 || code == 98 || code == 118) #endif { keypad = Qt::KeypadModifier; } // Ctrl-Alt-Backspace exits qws if (ctrl && alt && keyCode == Qt::Key_Backspace) { qApp->quit(); } if (keyCode == Qt::Key_Alt) { alt = !release; } else if (keyCode == Qt::Key_Control) { ctrl = !release; } else if (keyCode == Qt::Key_Shift) { shift = !release; } else if (keyCode == Qt::Key_CapsLock && release) { caps = !caps; #if defined(Q_OS_LINUX) char leds; ioctl(0, KDGETLED, &leds); leds = leds & ~LED_CAP; if (caps) leds |= LED_CAP; ioctl(0, KDSETLED, leds); #endif } if (keyCode != Qt::Key_unknown) { bool bAlt = alt; bool bCtrl = ctrl; bool bShift = shift; int unicode = 0; if (code < keyMSize) { if (!extended) { bool bCaps = shift || (caps ? QChar(keyMap()[code].unicode).isLetter() : false); if (bCtrl) unicode = keyMap()[code].ctrl_unicode ? keyMap()[code].ctrl_unicode : 0xffff; else if (bCaps) unicode = keyMap()[code].shift_unicode ? keyMap()[code].shift_unicode : 0xffff; else unicode = keyMap()[code].unicode ? keyMap()[code].unicode : 0xffff; #ifndef QT_QWS_USE_KEYCODES } else if (extended==1) { if (code == 53) unicode = '/'; #endif } } modifiers = 0; if (bAlt) modifiers |= Qt::AltModifier; if (bCtrl) modifiers |= Qt::ControlModifier; if (bShift) modifiers |= Qt::ShiftModifier; if (keypad) modifiers |= Qt::KeypadModifier; // looks wrong -- WWA bool repeat = false; if (prevuni == unicode && prevkey == keyCode && !release) repeat = true; processKeyEvent(unicode, keyCode, modifiers, !release, repeat); if (!release) { prevuni = unicode; prevkey = keyCode; } else { prevkey = prevuni = 0; } } if (softwareRepeat && !release) beginAutoRepeat(prevuni, prevkey, modifiers); else endAutoRepeat(); extended = 0; }
static void createKeyMap() { for (unsigned int i = 1; i < 25; i++) { StringBuilder builder; builder.append('F'); builder.appendNumber(i); String key = builder.toString(); keyMap().set(key, key); } keyMap().set(ASCIILiteral("Alt_L"), ASCIILiteral("Alt")); keyMap().set(ASCIILiteral("ISO_Level3_Shift"), ASCIILiteral("Alt")); keyMap().set(ASCIILiteral("Menu"), ASCIILiteral("Alt")); keyMap().set(ASCIILiteral("Shift_L"), ASCIILiteral("Shift")); keyMap().set(ASCIILiteral("Shift_R"), ASCIILiteral("Shift")); keyMap().set(ASCIILiteral("Down"), ASCIILiteral("Down")); keyMap().set(ASCIILiteral("End"), ASCIILiteral("End")); keyMap().set(ASCIILiteral("Return"), ASCIILiteral("Enter")); keyMap().set(ASCIILiteral("KP_Enter"), ASCIILiteral("Enter")); keyMap().set(ASCIILiteral("Home"), ASCIILiteral("Home")); keyMap().set(ASCIILiteral("Insert"), ASCIILiteral("Insert")); keyMap().set(ASCIILiteral("Left"), ASCIILiteral("Left")); keyMap().set(ASCIILiteral("Next"), ASCIILiteral("PageDown")); keyMap().set(ASCIILiteral("Prior"), ASCIILiteral("PageUp")); keyMap().set(ASCIILiteral("Right"), ASCIILiteral("Right")); keyMap().set(ASCIILiteral("Up"), ASCIILiteral("Up")); keyMap().set(ASCIILiteral("Delete"), ASCIILiteral("U+007F")); keyMap().set(ASCIILiteral("Tab"), ASCIILiteral("U+0009")); keyMap().set(ASCIILiteral("ISO_Left_Tab"), ASCIILiteral("U+0009")); keyMap().set(ASCIILiteral("BackSpace"), ASCIILiteral("U+0008")); keyMap().set(ASCIILiteral("space"), ASCIILiteral("U+0020")); keyMap().set(ASCIILiteral("Escape"), ASCIILiteral("U+001B")); keyMap().set(ASCIILiteral("Print"), ASCIILiteral("PrintScreen")); // Keypad location keyMap().set(ASCIILiteral("KP_Left"), ASCIILiteral("Left")); keyMap().set(ASCIILiteral("KP_Right"), ASCIILiteral("Right")); keyMap().set(ASCIILiteral("KP_Up"), ASCIILiteral("Up")); keyMap().set(ASCIILiteral("KP_Down"), ASCIILiteral("Down")); keyMap().set(ASCIILiteral("KP_Prior"), ASCIILiteral("PageUp")); keyMap().set(ASCIILiteral("KP_Next"), ASCIILiteral("PageDown")); keyMap().set(ASCIILiteral("KP_Home"), ASCIILiteral("Home")); keyMap().set(ASCIILiteral("KP_End"), ASCIILiteral("End")); keyMap().set(ASCIILiteral("KP_Insert"), ASCIILiteral("Insert")); keyMap().set(ASCIILiteral("KP_Delete"), ASCIILiteral("U+007F")); addCharactersToKeyMap('a', 'z'); addCharactersToKeyMap('A', 'Z'); addCharactersToKeyMap('0', '9'); }