Ejemplo n.º 1
0
void ReportKeycodeAction(u8 keycode, bool add) {
  u8 index;

  if (IsModifier(keycode)) {
    index = 0;
  } else {
    // Add one to skip the modifier byte.
    index = 1 + (keycode / 8);
  }

  u8 nth_bit = (keycode % 8);

  if (add)
    BIT_SET(report_data[index], nth_bit);
  else
    BIT_CLR(report_data[index], nth_bit);

  changed = true;
}
Ejemplo n.º 2
0
bool Keyboard::HandleKeyEvent(const SDL_Event& evnt)
{
  // Not a registred event
  if (!IsRegistredEvent(evnt.type))
    return false;

  Key_Event_t event_type;
  switch(evnt.type) {
  case SDL_KEYDOWN:
    event_type = KEY_PRESSED;
    break;
  case SDL_KEYUP:
    event_type = KEY_RELEASED;
    break;
  default:
    return false;
  }

  //Handle input text for Chat session in Network game
  if (Game::GetInstance()->chatsession.CheckInput()) {
    if (event_type == KEY_PRESSED)
      Game::GetInstance()->chatsession.HandleKeyPressed(evnt);
    else if (event_type == KEY_RELEASED)
      Game::GetInstance()->chatsession.HandleKeyReleased(evnt);
    return false;
  }

  SDLKey basic_key_code = evnt.key.keysym.sym;

#ifdef DEBUG
  if (IsLOGGING("killsynchro")
      && basic_key_code == SDLK_k
      && event_type == KEY_RELEASED) {
    fprintf(stderr, "\n\nKILLING NETWORK SYNCHRONISATION!\n\n");
    RandomSync().SetSeed(0);
  }
#endif

  // Also ignore real key code of a modifier, fix bug #15238
  if (IsModifier(basic_key_code)) {
    int modifier_changed = modifier_only_bits ^ GetModifierBits();
    if (event_type == KEY_RELEASED) {
      for (std::set<SDLKey>::const_iterator it = pressed_keys.begin(); it != pressed_keys.end(); it++ ) {
        int key_code = *it + MODIFIER_OFFSET * modifier_changed;
        HandleKeyComboEvent(key_code, KEY_RELEASED);
      }
    } else if (modifier_only_bits && event_type == KEY_PRESSED) {
      for (std::set<SDLKey>::const_iterator it = pressed_keys.begin(); it != pressed_keys.end(); it++ ) {
        int key_code = *it + MODIFIER_OFFSET * modifier_only_bits;
        HandleKeyComboEvent(key_code, KEY_RELEASED);
      }
    }
    modifier_only_bits = GetModifierBits();
    return false;
  }
#ifdef MAEMO
  if (SDL_GetModState() & KMOD_MODE) {
    if (basic_key_code == SDLK_LEFT) basic_key_code = SDLK_UP;
    if (basic_key_code == SDLK_RIGHT) basic_key_code = SDLK_DOWN;
  }
#endif

  int key_code;
  int previous_modifier_bits = modifier_bits;
  modifier_bits = GetModifierBits();

  if (modifier_bits != previous_modifier_bits) {
    std::set<SDLKey>::const_iterator it = pressed_keys.find(basic_key_code);
    if (it !=  pressed_keys.end()) {
      key_code = basic_key_code + MODIFIER_OFFSET * previous_modifier_bits;
      HandleKeyComboEvent(key_code, KEY_RELEASED);
      if (key_code != basic_key_code)
        HandleKeyComboEvent(basic_key_code, KEY_RELEASED);
      pressed_keys.erase(basic_key_code);
      if (event_type == KEY_PRESSED) {
        key_code = basic_key_code + MODIFIER_OFFSET * modifier_bits;
        HandleKeyComboEvent(key_code, KEY_PRESSED);
        pressed_keys.insert(basic_key_code);
      }
      return true;
    }
  }

  if (event_type == KEY_PRESSED) {
    key_code = basic_key_code + (MODIFIER_OFFSET * modifier_bits);
    HandleKeyComboEvent(key_code, KEY_PRESSED);
    if (previous_modifier_bits ^ modifier_bits) {
      key_code = basic_key_code + (MODIFIER_OFFSET * previous_modifier_bits);
      HandleKeyComboEvent(key_code, KEY_RELEASED);
    }
    pressed_keys.insert(basic_key_code);
  } else {
    ASSERT(event_type == KEY_RELEASED);
    key_code = basic_key_code + (MODIFIER_OFFSET * previous_modifier_bits);
    HandleKeyComboEvent(key_code, KEY_RELEASED);
    if (key_code != basic_key_code)
      HandleKeyComboEvent(basic_key_code, KEY_RELEASED);
    pressed_keys.erase(basic_key_code);
  }
  return true;
}