예제 #1
0
//--------------------------------------------------------------------------
//  Print all keys
//--------------------------------------------------------------------------
void CKeyMap::Print (FILE* f)
{
  // Iterate over keysets
  std::map<Tag,CKeySet*>::iterator i;
  for (i=kset.begin(); i!=kset.end(); i++) {
    CKeySet *pKeySet = i->second;

    // Format key set unique ID
    char s[8];
    TagToString (s, pKeySet->GetTag());
    fprintf (f, "KeySet '%s' %s\n", s, pKeySet->GetName());

    // Iterate over key definitions within the keyset
    std::map<Tag,CKeyDefinition*>::iterator j;
    for (j=pKeySet->dkey.begin(); j!=pKeySet->dkey.end(); j++) {
      CKeyDefinition *pKeyDef = j->second;

      // Format key definition unique ID
      char sId[8];
      TagToString (sId, pKeyDef->GetTag());

      // Format key code
      char sCode[32];
      formatKeyCode (sCode, pKeyDef->GetCode());

      fprintf (f, "  '%s' %-40s  %s\n", sId, pKeyDef->GetName(), sCode);
    }
  }
}
예제 #2
0
//-------------------------------------------------------------------------
//  Change group callback if key is redirected
//-------------------------------------------------------------------------
//  Activate key in group (simulate a key stroke)
//  The group is taken from the Keydef in case of redirection
//-------------------------------------------------------------------------
bool CKeyMap::Stroke(Tag grp,Tag kid)
{ //--- find the Key set ---------------------------
  CKeySet *ks = FindKeySetById (grp);
  if (0 == ks)    return false;
  CKeyDefinition *kdf = ks->GetKeyByTag(kid);
  if (0 == kdf)   return false;
  //--- Group Redirection --------------------------
  Tag        ngp = kdf->GetSet();
  ks             =   FindKeySetById (ngp);
  KeyGroupCB  cb = ks->GetCB();
  return (cb)(kdf,kdf->GetCode()) ;
}
예제 #3
0
//--------------------------------------------------------------------------
//  Save keyboard mapping to file
//--------------------------------------------------------------------------
void CKeyMap::SaveCurrentConfig()
{ char codk[128];
  char stag[8];
  int i;
  CStreamFile sf;
  std::map<Tag,CKeySet*>::const_iterator it;
  std::map<Tag,CKeyDefinition*>::const_iterator kit;
  CKeySet        * pset;
  CKeyDefinition * pkey;
  sf.OpenWrite("System/Keymap.txt");
  //
  // file header and version
  //
  sf.WriteString("//=================================================");
  sf.WriteString("// Please note that Keyset are ordered by name     ");
  sf.WriteString("// Menus should come first as they intercept keys  ");
  sf.WriteString("// that may be dispatched to lower entity such as  ");
  sf.WriteString("// Aircraft or ground vehicles                     ");
  sf.WriteString("//=================================================");
  sf.DebObject();
  sf.WriteTag('vers', "---- configuration version ----");
  sf.WriteInt(vers);
  for(it = kset.begin(); it != kset.end(); it++)
  {	pset = it->second;
    sf.WriteTag('kset', "=== KeySet Definition File ===");
    TagToString(stag, it->first);
    sf.WriteString(stag);
    sf.WriteTag('bgno', "========== BEGIN OBJECT ==========");
    sf.WriteTag('name', "---- key set name ----");
    sf.WriteString(pset->GetName());
    sf.WriteTag('user', "---- user can modify ----");
    sf.WriteInt(pset->GetUserModifiableState());
    sf.WriteTag('enab', "---- enabled ----");
    sf.WriteInt(pset->GetEnabledState());
    for(kit = pset->dkey.begin(); kit != pset->dkey.end(); kit++)
      { pkey = kit->second;
        sf.WriteTag('kkey', "---- key definition ----");
        sf.DebObject();
        sf.WriteTag('kyid', "---- key ID ----");
        TagToString(stag, kit->first);
        sf.WriteString(stag);
        sf.WriteTag('name', "---- key name ----");
        sf.WriteString(pkey->GetName());
        sf.WriteTag('code', "---- key code & modifier ----");
				i = pkey->GetCode();
				formatKeyCode(codk,i,0);
				sf.WriteString(codk);
        sf.WriteTag('user', "---- user definable ----");
        sf.WriteInt(pkey->IsUserMod());
        sf.WriteTag('enab', "---- enabled ----");
        sf.WriteInt(pkey->IsEnabled());
        sf.EndObject();
      }
      sf.EndObject();
    }
  // File end
  //
  sf.EndObject();
  sf.Close();
	return;
}