Exemple #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);
    }
  }
}
Exemple #2
0
//----------------------------------------------------------------------
//  Init the button list for the requested joystick
//----------------------------------------------------------------------
void CFuiAxis::ButtonList(int No)
{ jsp = jsm->GetJoystickNo(No);
  if (0 == jsp)     return;
  devPOP->SetButtonText(devMENU[No]);
  butBOX.EmptyIt();
  //-----Locate joystick descriptor
	int       end = jsp->nbt;
  char      txt[128];
  char     *ktx = "";
  CButLine *btl = 0;
  for (int k=0; k<end; k++)
  { CSimButton     *but = jsp->GetButton(k);
    CKeyDefinition *kdf = (but)?(but->GetKey()):(0);
    ktx = (kdf)?(kdf->GetName()):("");
    sprintf(txt,"Button %02d",k);
    btl = new CButLine;
    btl->SetName(txt);
    btl->SetKeyText(ktx);
    butBOX.AddSlot(btl);
  }
  butBOX.Display();
	//--- Set Hat control ---------------------------
	sprintf(txt,"This device has %d HAT",jsp->hNumber());
	SetChildText('labH',txt);
	char	use = jsp->HatUsed();
	chkHAT->SetState(use);
	HatControl();
  return;
}
Exemple #3
0
//------------------------------------------------------------------------------
//  Bind Key (idk) to global function f
//  NOTE: As keys menu are first searched, when a Key is redefined 
//  by a lower group, then the menu key will redirect the call to the lower 
//  entity
//  Example: GWIN is the menu Key to display GPS
//           When aircraft bind the 'gwin' key, the call is redirected to aircraft
//------------------------------------------------------------------------------
void CKeyMap::Bind (Tag id, KeyCallbackPtr f,char tp)
{ CKeyDefinition *kdf = FindKeyDefinitionById (id);
  if (0 == kdf)       return; 
  kdf->SetSet(lgrp);  
  kdf->Bind(f);
  kdf->SetType(tp);
  return;
}
Exemple #4
0
//------------------------------------------------------------------------------
//  Unassign code from any key definition existing in the set
//	NOTE: The key is unassigned from the current set only
//------------------------------------------------------------------------------
CKeyDefinition *CKeyMap::UnAssign(int cde,CKeyDefinition *kdf)
{ CKeySet					*set = FindKeySetById(kdf->GetSet());
  CKeyDefinition	*kpv = set->GetKeyByCode(cde);
  if (0   == kpv)         return 0;
  kdf->SetCode(0);			// remove code from actual
	kpv->SetCode(0);			// remove code from previous
	set->ClearCode(cde);
  return kpv;
}
Exemple #5
0
//-------------------------------------------------------------------------
// Reset the default key
//  NOTE:  
//    The actual code of the key should be removed from the code table
//    The new code key should be entered into the code table
//-------------------------------------------------------------------------
void CKeySet::SetDefaultValues(CKeyFile *def)
{ std::map<Tag,CKeyDefinition*>::iterator kd = dkey.begin();
  for (kd = dkey.begin(); kd != dkey.end(); kd++)
  { CKeyDefinition* kdf = kd->second;
    int cde = (def)?(def->GetDefault(kset,kdf->GetTag())):(0);
    if (cde) globals->kbd->SwapCode(kdf,cde);
  }
  return;
}
Exemple #6
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()) ;
}
Exemple #7
0
//-------------------------------------------------------------------------
//  Enter a key definition
//  The key is registered in 2 maps
//  dkey by the generic tag
//  ckey by the keyboard code (for fast access)
//-------------------------------------------------------------------------
void CKeySet::Enter(CKeyDefinition *kdf)
{ Tag gen   = kdf->GetTag();
  int cod   = kdf->GetCode();
	dkey[gen] = kdf;							// Register by Tag
  //---Check that the code is unique in the set --
  std::map<int,CKeyDefinition *>::iterator it = ckey.find(cod);
	//---Register if key is unic in set ------
  if (it == ckey.end())	{ ckey[cod] = kdf; return;	}
  //----Can't have same code for 2 key ------
  if (0 == cod)              return;
  if ((*it).second == kdf)   return; 
  //----------------------------------------------
	kdf->SetCode(0);							// Clear Keyboard key
  CKeyDefinition *pvk = (*it).second;
  char tag1[8];
  TagToString(tag1,kdf->GetTag());
  char tag2[8];
  TagToString(tag2,pvk->GetTag());
  WARNINGLOG("<Kyid> %s ignored (same keyboard code than <Kyid> %s)",tag1,tag2);
  return;
}
Exemple #8
0
//------------------------------------------------------------------------------
//  Keyboard Key pressed
//------------------------------------------------------------------------------
void CKeyMap::KeyPress (U_INT key, EKeyboardModifiers mod)
{ // Translate key and modifier into keycode
  int  code = (mod << 16) + key;
  bool handled = false;
  //--- special detection mode ------------------------------
  if(m_bKeyDetect && m_fKeyCallback)
  {
    /// \todo unbind if this key code is already asigned
    if (m_fKeyCallback(m_winID, code)) return;
  }
  //---Standard key -----------------------------------------
  for (U_INT k=0; (k<oset.size()); k++)
  {   CKeySet *ks = oset[k];
      CKeyDefinition *kdf = ks->GetKeyByCode(code);
      if (0 == kdf)       continue;
      //---Call the redirected group key callback -----------
      Tag        ngp = kdf->GetSet();
      ks             =   FindKeySetById (ngp);
      KeyGroupCB  cb = ks->GetCB();
      handled = (cb)(kdf,code);
			if (handled) return;
  }
  return;
}
Exemple #9
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;
}