KeyMap KeyMap::standard(KeyMap::Model model, KeyMap::Layout layout){ if(model == NO_MODEL || layout == NO_LAYOUT) return KeyMap(); if(model == K70){ // Build the K70 tables if not done yet if(!K70Pos[0].positions){ for(uint keyboard = 0; keyboard < KEYLAYOUT_COUNT; keyboard++){ uint j = 0; uint count = K95Pos[keyboard].count; const KeyPos* keyIn = K95Pos[keyboard].positions; KeyPos* keyOut = new KeyPos[K70Pos[keyboard].count]; K70Pos[keyboard].positions = keyOut; for(uint i = 0; i < count; i++){ // Remove anything before X-start (G keys) as well as the M keys if(keyIn[i].x < K70_X_START || !strcmp(keyIn[i].name, "mr") || !strcmp(keyIn[i].name, "m1") || !strcmp(keyIn[i].name, "m2") || !strcmp(keyIn[i].name, "m3")) continue; keyOut[j] = keyIn[i]; keyOut[j].x -= K70_X_START; j++; } } } // Return K70 positions return KeyMap(model, layout, K70Pos[layout].count, K70_WIDTH, K70Pos[layout].positions); } // Return K95 positions return KeyMap(model, layout, K95Pos[layout].count, K95_WIDTH, K95Pos[layout].positions); }
EXPORT_C TInt CSDL::SetSDLCode(TInt aScanCode, TInt aSDLCode) { const TInt current = GetSDLCode(aScanCode); if(aScanCode >= 0 && aScanCode < MAX_SCANCODE) KeyMap()[aScanCode] = static_cast<SDLKey>(aSDLCode); return current; }
EXPORT_C TInt CSDL::GetSDLCode(TInt aScanCode) { if(aScanCode < 0) return MAX_SCANCODE; if(aScanCode >= MAX_SCANCODE) return -1; return KeyMap()[aScanCode]; }
//AVS // perform keymap switching int KeyTranslator::switchMap(TKeyDef& tk) { if ( mapArray.IsEmpty() ) { return currentKeyMap = -1; }; int i = mapArray.Find(KeyMap(tk)); if ( i != INT_MAX ) { if (currentKeyMap == i) currentKeyMap = mainKeyMap; // restore to default else currentKeyMap = i; return 1; }; return 0; };
void USBKeyboardDevice (TUSBKeyboardDevice *pThis, TUSBDevice *pDevice) { assert (pThis != 0); USBDeviceCopy (&pThis->m_USBDevice, pDevice); pThis->m_USBDevice.Configure = USBKeyboardDeviceConfigure; pThis->m_pReportEndpoint = 0; pThis->m_pKeyPressedHandler = 0; pThis->m_pSelectConsoleHandler = 0; pThis->m_pShutdownHandler = 0; pThis->m_pKeyStatusHandlerRaw = 0; pThis->m_pURB = 0; pThis->m_pReportBuffer = 0; pThis->m_ucLastPhyCode = 0; pThis->m_hTimer = 0; KeyMap (&pThis->m_KeyMap); pThis->m_pReportBuffer = malloc (BOOT_REPORT_SIZE); assert (pThis->m_pReportBuffer != 0); }
KeyMap KeyMap::fromName(const QString &name){ QStringList list = name.trimmed().split(" "); if(list.length() != 2) return KeyMap(); return standard(getModel(list[0]), getLayout(list[1])); }
void RebindWidget::setBind(KbBind* newBind, KbProfile* newProfile){ bind = newBind; profile = newProfile; setSelection(QStringList()); // Populate typing keys by position ui->typingBox->clear(); ui->typingBox->addItem(" "); typingKeys.clear(); // Use the K95 map as it has all keys const KeyMap& map = KeyMap(KeyMap::K95, bind->map().layout()); foreach(const QString& name, map.byPosition()){ KeyAction action(KbBind::defaultAction(name)); if(action.isNormal() && !modKeys.contains(name) && !fnKeys.contains(name) && !numKeys.contains(name) && !mediaKeys.contains(name) && name != "enter" && name != "tab" && name != "bspace"){ const Key& pos = map[name]; QString friendly = pos.friendlyName(); ui->typingBox->addItem(friendly); typingKeys.append(name); } } typingKeys << "enter" << "tab" << "bspace"; ui->typingBox->addItem("Enter"); ui->typingBox->addItem("Tab"); ui->typingBox->addItem("Backspace"); if(!map.isISO()){ // Add ISO backslash (aka KEY_102ND) to ANSI options typingKeys << "bslash_iso"; ui->typingBox->addItem("Backslash (ISO layout)"); } // Populate mode list ui->modeBox->clear(); ui->modeBox->addItem(" "); ui->modeBox->addItem("(Previous)"); ui->modeBox->addItem("(Next)"); int idx = 1; foreach(KbMode* mode, newProfile->modes()) ui->modeBox->addItem(QString("%1: %2").arg(idx++).arg(mode->name())); // Enable/disable DPI based on device if(bind->isMouse()){ ui->dpiButton->setEnabled(true); ui->dpiBox->setEnabled(true); ui->dpiWarning->hide(); // Fill DPI slots const KbPerf* perf = bind->perf(); for(int i = 0; i < KbPerf::DPI_COUNT; i++){ bool sniper = (i == 0); int boxIdx = i + 3; QPoint dpi = perf->dpi(i); QString text = tr(sniper ? "Sniper:\t%1 x %2" : "%3:\t%1 x %2").arg(dpi.x()).arg(dpi.y()); if(!sniper) text = text.arg(i); ui->dpiBox->setItemText(boxIdx, text); } } else { ui->dpiButton->setEnabled(false); ui->dpiBox->setEnabled(false); ui->dpiWarning->show(); } // Always disable custom DPI boxes until selected ui->dpiCustXBox->setEnabled(false); ui->dpiCustYBox->setEnabled(false); ui->dpiCustLabel->setEnabled(false); }
// AVS // completelly rewrited to support new conceptions int TMapLoader::Load(const char * filename, const char * szActiveEmul) { char buf[256]; int bufLen; ifstream inpfile(filename); KeyTrans.DeleteAllDefs(); Charmap.init(); // it is an array for store [...] ... [end ...] parts from file stringArray SA(0,0,sizeof(string)); int AllOk = 0; while ( inpfile ) { getline(inpfile, buf, 255); bufLen = strlen(buf); if ( !bufLen ) continue; if ( buf[0] == '[' && buf[bufLen-1] == ']' ) { // is a part splitter [...] string temps(buf); if (!normalizeSplitter(temps)) { printm(0, FALSE, MSG_KEYUNEXPLINE, temps.c_str()); AllOk = 0; break; }; // if a comment if ( stricmp(temps.c_str(),"[comment]") == 0 ) { #ifdef KEYDEBUG printit(temps.c_str()); #endif if ( !getLongComment(inpfile, buf, sizeof(buf)) ) { printm(0, FALSE, MSG_KEYUNEXPEOF); break; }; #ifdef KEYDEBUG printit("\r \r"); #endif continue; }; string back = temps; // prepare line for make it as [end ...] // and check it if ( strnicmp(back.c_str(), "[global]", 8) == 0 ) {} // do nothing else if ( strnicmp(back.c_str(), "[keymap", 7) == 0 ) { // DJGPP also uses erase rather than remove (Paul Brannan 6/23/98) #ifndef __BORLANDC__ back.erase(7); #else back.remove(7); #endif back += "]"; } else if ( strnicmp(back.c_str(), "[charmap", 8) == 0 ) { // Paul Brannan 6/23/98 #ifndef __BORLANDC__ back.erase(8); #else back.remove(8); #endif back += "]"; } else if ( strnicmp(back.c_str(), "[config", 7) == 0 ) { // Paul Brannan 6/23/98 #ifndef __BORLANDC__ back.erase(7); #else back.remove(7); #endif back += "]"; } else { // cerr << "Unexpected token " << back << endl; printm(0, FALSE, MSG_KEYUNEXPTOK, back.c_str()); break; }; back.insert(1,"END "); // now it looks like [END ...] #ifdef KEYDEBUG printit(temps.c_str()); #endif int ok = 0; // fetch it to temps while ( 1 ) { getline(inpfile, buf, sizeof(buf)); bufLen = strlen(buf); if ( !bufLen ) break; if ( buf[0] == '[' && buf[bufLen-1] == ']' ) { string t(buf); if ( !normalizeSplitter(t) ) break; if ( stricmp(t.c_str(),back.c_str()) == 0 ) { ok = 1; break; }; // AVS 31.12.97 fix [comment] block inside another block if ( stricmp(t.c_str(),"[comment]") == 0 && getLongComment(inpfile, buf, sizeof(buf)) ) continue; break; }; temps += "\n"; temps += buf; }; if ( !ok ) { // cerr << "Unexpected end of file or token" << endl; printm(0, FALSE, MSG_KEYUNEXP); AllOk = 0; break; }; #ifdef KEYDEBUG printit("\r \r"); #endif AllOk = SA.Add(temps);; if ( !AllOk ) break; } else { // cerr << "Unexpected line '" << buf << "'\n"; printm(0, FALSE, MSG_KEYUNEXPLINE, buf); AllOk = 0; break; }; }; inpfile.close(); if ( !AllOk ) return 0; // now all file are in SA, comments are stripped int i = LookForPart(SA, "global", ""); if ( i == INT_MAX ) { // cerr << "No [GLOBAL] definition!" << endl; printm(0, FALSE, MSG_KEYNOGLOBAL); return 0; }; if ( !LoadGlobal(SA[i]) ) { return 0; }; // look for need configuration i = LookForPart(SA, "config", szActiveEmul); if ( i == INT_MAX ) { // cerr << "No [CONFIG " << szActiveEmul << "]\n"; printm(0, FALSE, MSG_KEYNOCONFIG, szActiveEmul); return 0; }; // cerr << "use configuration: " << szActiveEmul << endl; printm(0, FALSE, MSG_KEYUSECONFIG, szActiveEmul); BOOL hadKeys = FALSE; string config = SA[i]; // parse it while ( config.length() ) { buf[0] = 0; getline(config,buf,sizeof(buf)); bufLen = strlen(buf); if ( !bufLen || (buf[0] == '[' && buf[bufLen-1] == ']') ) continue; if ( strnicmp(buf,"keymap",6) == 0 ) { string orig(buf); printit("\t"); printit(buf); printit("\n"); char * mapdef = strtok(buf,":"); char * switchKey = strtok(NULL,"\n"); if ( !KeyTrans.mapArray.IsEmpty() && switchKey == NULL ) { // cerr << "no switch Key for '" << mapdef // << "'" << endl; printm(0, FALSE, MSG_KEYNOSWKEY, mapdef); break; }; if ( KeyTrans.mapArray.IsEmpty() ) { if ( switchKey != NULL ) { // create default keymap // cerr << "You cannot define switch key for default keymap -> ignored" // << endl; printm(0, FALSE, MSG_KEYCANNOTDEF); }; TKeyDef empty; KeyTrans.mapArray.Add(KeyMap(string(mapdef))); KeyTrans.switchMap(empty); // set it as current keymap KeyTrans.mainKeyMap = KeyTrans.currentKeyMap; } else { string keydef(switchKey); keydef += " !*!*!*"; // just for check WORD vk_code; DWORD control; switchKey = ParseKeyDef(keydef.c_str(),vk_code,control); if ( switchKey != NULL ) { TKeyDef swi(NULL,control,vk_code); if ( KeyTrans.switchMap(swi) > 0 ) { // cerr << "Duplicate switching key\n"; printm(0, FALSE, MSG_KEYDUPSWKEY); break; }; KeyTrans.mapArray.Add(KeyMap(swi, orig)); KeyTrans.switchMap(swi); // set it as current keymap } }; mapdef+=7; // 'keymap ' // now load defined keymaps to current while ((mapdef != NULL)&& (mapdef = strtok(mapdef,TOKEN_DELIMITERS)) != NULL ) { i = LookForPart(SA,"keymap",mapdef); if ( i == INT_MAX ) { // cerr << "Unknown KEYMAP " << mapdef << endl; printm(0, FALSE, MSG_KEYUNKNOWNMAP, mapdef); } else { mapdef = strtok(NULL,"\n"); // strtok is used in LoadKeyMap // so - save pointer! hadKeys = LoadKeyMap(SA[i]); // load it }; }; } else if ( strnicmp(buf,"charmap",7) == 0 ) { printit("\t"); printit(buf); printit("\n"); char * mapdef = buf + 8;// 'charmap ' int SuccesLoaded = 0; // now load defined charmaps to current while ((mapdef != NULL)&& (mapdef = strtok(mapdef,TOKEN_DELIMITERS)) != NULL ) { i = LookForPart(SA,"charmap",mapdef); if ( i == INT_MAX ) { // cerr << "Unknown KEYMAP " << mapdef << endl; printm(0, FALSE, MSG_KEYUNKNOWNMAP, mapdef); } else { mapdef = strtok(NULL,"\n"); // strtok is used in LoadKeyMap // so - save pointer! if (LoadCharMap(SA[i])) // load it SuccesLoaded++; }; }; if (!SuccesLoaded) { // cerr << "No charmaps loaded\n"; printm(0, FALSE, MSG_KEYNOCHARMAPS); Charmap.init(); }; /* strtok(buf," "); char* name = strtok(NULL," "); if ( name == NULL ) { cerr << "No name for CHARMAP" << endl; } else { i = LookForPart(SA,"charmap", name); if ( i == INT_MAX ) { cerr << "Unknown CHARMAP " << name << endl; } else { LoadCharMap(SA[i]); }; }; */ } else { // cerr << "unexpected token in " << szActiveEmul << endl; printm(0, FALSE, MSG_KEYUNEXPTOKIN, szActiveEmul); } } if ( hadKeys) { TKeyDef empty; KeyTrans.switchMap(empty); // switch to default KeyTrans.mainKeyMap = KeyTrans.currentKeyMap; // save it's number // cerr << "There are " << (KeyTrans.mapArray.GetItemsInContainer()) << " maps\n"; char s[12]; // good enough for a long int (32-bit) itoa(KeyTrans.mapArray.GetItemsInContainer(), s, 10); printm(0, FALSE, MSG_KEYNUMMAPS, s); return 1; }; return 0; }