xbmc从onEvent到onkey创建CKey对象的过程

注我们以遥控器音量加键为说明例子

//xbmc/Application.cpp
bool CApplication::OnEvent(XBMC_Event& newEvent)
{
  switch(newEvent.type)
  {
    case XBMC_QUIT: //退出xbmc
        ...
        CApplicationMessenger::Get().Quit();
    break;

    case XBMC_KEYDOWN:
        g_application.OnKey(g_Keyboard.ProcessKeyDown(newEvent.key.keysym));
    break;  
  }
}
/*
xbmc/input/KeyboardStat.cpp
*/
const CKey CKeyboardStat::ProcessKeyDown(XBMC_keysym& keysym)
{ uint8_t vkey;
  wchar_t unicode;
  char ascii;
  uint32_t modifiers;
  unsigned int held;
  XBMCKEYTABLE keytable;
  ...
   //这里一句输出了:Keyboard: scancode: 0x18, sym: 0x002b, unicode: 0x0000, modifier: 0x0
  CLog::Log(LOGDEBUG, "Keyboard: scancode: 0x%02x, sym: 0x%04x, unicode: 0x%04x, modifier: 0x%x", 
  keysym.scancode, keysym.sym, keysym.unicode, keysym.mod);

 if (LookupSymAndUnicodePeripherals(keysym, &vkey, &ascii))
  {
    CLog::Log(LOGDEBUG, "%s - keypress translated by a HID peripheral", __FUNCTION__);
  }

  // Continue by trying to match both the sym and unicode. This will identify
  else if (KeyTableLookupSymAndUnicode(keysym.sym, keysym.unicode, &keytable))
  {
    vkey = keytable.vkey;
    ascii = keytable.ascii;
  }

  // If we failed to match the sym and unicode try just the unicode. This
  else if (KeyTableLookupUnicode(keysym.unicode, &keytable))
  {
    vkey = keytable.vkey;
    ascii = keytable.ascii;
  }
  // If there is still no match try the sym我们按音量加进入了这里
  else if (KeyTableLookupSym(keysym.sym, &keytable))
  {
    vkey = keytable.vkey;
    if (keytable.unicode == 0 && unicode != 0)
      unicode = 0;
    else if (keysym.unicode > 32 && keysym.unicode < 128)
      ascii = unicode & 0x7f;
  }
  ...
  //我们点击遥控器音量加到这里是 vkey:+, unicode:0x0000, ascii:null, modifiers:0x0000, held:0
  CKey key(vkey, unicode, ascii, modifiers, held);

  return key;
}
/*
xbmc/input/XBMC_keytable.cpp
*/
bool KeyTableLookupSym(uint16_t sym, XBMCKEYTABLE* keytable)
{
  ...
  // Look up the sym in XBMCKeyTable
  for (int i = 0; i < XBMCKeyTableSize; i++)
  { if (sym == XBMCKeyTable[i].sym)
    { *keytable = XBMCKeyTable[i];
      return true;
    }
  }
  return false;
}

这里会查找XBMCKeyTable这个数组,以找到sym号相同的的数组。我们知道sym为0x002b,这个
值是在AndroidKey.cpp将键盘scancode转化为sym而来。

/*
xbmc/input/XBMC_keytable.h
*/
typedef struct struct_XBMCKEYTABLE
{
  uint16_t sym;
  uint16_t unicode;
  char     ascii;
  uint32_t    vkey;
  const char* keyname;
}

static const XBMCKEYTABLE XBMCKeyTable[] =
{
  ...
  // Misc printing characters
  { XBMCK_PLUS,                 '+',  '+', XBMCVK_PLUS,            "plus" }
  ...
}

到此,我们就解析完了CKey对象的创建过程,然后它被传递给了

//xbmc/Application.cpp
bool CApplication::OnKey(const CKey& key)
{
  // get the current active window
  int iWin = GetActiveWindowID();
  // this will be checked for certain keycodes that need
  // special handling if the screensaver is active
  CAction action = CButtonTranslator::GetInstance().GetAction(iWin, key);
    ....

  if (!key.IsAnalogButton())
    CLog::LogF(LOGDEBUG, "%s pressed, action is %s", 
        g_Keyboard.GetKeyName((int) key.GetButtonCode()).c_str(), action.GetName().c_str());

  return ExecuteInputAction(action);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值