bool
DependingPressingPeriodKeyToKey::remap(RemapParams& remapParams)
{
    bool result = keytokey_[KeyToKeyType::FROM].remap(remapParams);
    if (! result) {
        if (remapParams.params.ex_iskeydown) {
            // another key is pressed.
            dokeydown();
        }
        return false;
    }

    if (remapParams.params.ex_iskeydown) {
        target_ = this;
        active_ = true;
        periodtype_ = PeriodType::NONE;

        // clear temporary_flags (KeyToKeyType::FROM's flags)
        FlagStatus::set();
        savedflags_ = FlagStatus::makeFlags();

        fire_timer_.setTimeoutMS(periodMS_.get(PeriodMS::Type::SHORT_PERIOD));

    } else {
        dokeydown();
        dokeyup();
    }
    return true;
}
Esempio n. 2
0
static void
checkevent(void)
{
	GR_EVENT	event;

	GrGetNextEvent(&event);
	switch (event.type) {
		case GR_EVENT_TYPE_EXPOSURE:
			doexposure(&event.exposure);
			break;
		case GR_EVENT_TYPE_BUTTON_DOWN:
			dobuttondown(&event.button);
			break;
		case GR_EVENT_TYPE_BUTTON_UP:
			dobuttonup(&event.button);
			break;
		case GR_EVENT_TYPE_MOUSE_POSITION:
			doposition(&event.mouse);
			break;
		case GR_EVENT_TYPE_KEY_DOWN:
			dokeydown(&event.keystroke);
			break;
		case GR_EVENT_TYPE_CLOSE_REQ:
			GrClose();
			exit(0);
	}
}
bool
DependingPressingPeriodKeyToKey::remap(RemapPointingParams_scroll& remapParams)
{
    // We treat this event as another key has been pressed.
    dokeydown();
    return false;
}
bool
DependingPressingPeriodKeyToKey::remap(RemapPointingParams_relative& remapParams)
{
    // We treat this event as another key has been pressed.
    if (remapParams.params.ex_isbuttondown) {
        dokeydown();
    }
    return false;
}
bool
DependingPressingPeriodKeyToKey::remap(RemapConsumerParams& remapParams)
{
    // We treat this event as another key has been pressed.
    if (remapParams.params.ex_iskeydown) {
        dokeydown();
    }
    return false;
}
void DependingPressingPeriodKeyToKey::prepare(RemapParams& remapParams) {
  // Params_ScrollWheelEventCallback
  {
    auto params = remapParams.paramsBase.get_Params_ScrollWheelEventCallback();
    if (params) {
      if (interruptibleByScrollWheel_) {
        dokeydown();
      }
    }
  }
}
void DependingPressingPeriodKeyToKey::prepare(RemapParams& remapParams) {
  // Params_ScrollWheelEventCallback
  {
    auto params = remapParams.paramsBase.get_Params_ScrollWheelEventCallback();
    if (params) {
      if (interruptibleByScrollWheel_) {
        dokeydown(remapParams);
      }
    }
  }

  // Params_KeyboardEventCallBack, Params_KeyboardSpecialEventCallback, Params_RelativePointerEventCallback
  {
    bool iskeydown = false;
    if (remapParams.paramsBase.iskeydown(iskeydown)) {
      if (iskeydown) {
        // another key is pressed.
        dokeydown(remapParams);
      }
    }
  }
}
    bool
    DependingPressingPeriodKeyToKey::remap(RemapParams& remapParams)
    {
      // Params_ScrollWheelEventCallback
      {
        Params_ScrollWheelEventCallback* params = remapParams.paramsUnion.get_Params_ScrollWheelEventCallback();
        if (params) {
          if (interruptibleByScrollWheel_) {
            dokeydown();
          }
          return false;
        }
      }

      // Params_KeyboardEventCallBack, Params_KeyboardSpecialEventCallback, Params_RelativePointerEventCallback
      {
        bool iskeydown = false;
        if (remapParams.paramsUnion.iskeydown(iskeydown)) {
          if (remapParams.isremapped ||
              ! fromEvent_.changePressingState(remapParams.paramsUnion,
                                               FlagStatus::globalFlagStatus(),
                                               fromModifierFlags_)) {
            if (iskeydown) {
              // another key is pressed.
              dokeydown();
            }
            return false;
          }

          remapParams.isremapped = true;

          if (iskeydown) {
            target_ = this;
            active_ = true;
            periodtype_ = PeriodType::NONE;

            FlagStatus::globalFlagStatus().decrease(fromEvent_.getModifierFlag());
            FlagStatus::globalFlagStatus().decrease(pureFromModifierFlags_);

            beforeAfterKeys_.call_remap_with_VK_PSEUDO_KEY(EventType::DOWN);

            // We need save FlagStatus at keydown.
            // For example, "Change Space to Shift_L" is enabled,
            //
            // (1) Control_L down
            // (2) Space down
            // (3) Control_L up
            // (4) Space up        -> We should send Control_L+Space here.
            //
            // At (4), Control_L is not presssed.
            // We should send Control_L+Space at (4) because user pressed Space with Control_L at (2).
            //
            // Therefore, we need to save FlagStatus at (2).
            // And restore it at (4).
            //
            flagStatusWhenKeyPressed_ = FlagStatus::globalFlagStatus();

            unsigned int ms = periodMS_.get(PeriodMS::Type::SHORT_PERIOD);
            if (ms == 0) {
              fire_timer_callback(NULL, NULL);
            } else {
              fire_timer_.setTimeoutMS(ms);
            }

          } else {
            FlagStatus::globalFlagStatus().increase(fromEvent_.getModifierFlag());

            dokeydown();
            dokeyup();

            FlagStatus::globalFlagStatus().increase(pureFromModifierFlags_);

            beforeAfterKeys_.call_remap_with_VK_PSEUDO_KEY(EventType::UP);
          }
          return true;
        }
      }

      return false;
    }
bool DependingPressingPeriodKeyToKey::remap(RemapParams& remapParams) {
  // Params_KeyboardEventCallBack, Params_KeyboardSpecialEventCallback, Params_RelativePointerEventCallback
  {
    bool iskeydown = false;
    if (remapParams.paramsBase.iskeydown(iskeydown)) {
      if (remapParams.isremapped ||
          !fromEvent_.changePressingState(remapParams.paramsBase,
                                          FlagStatus::globalFlagStatus(),
                                          fromModifierFlags_)) {
        return false;
      }

      remapParams.isremapped = true;
      lastPhysicalEventType_ = remapParams.physicalEventType;

      if (iskeydown) {
        target_ = this;
        active_ = true;
        periodtype_ = PeriodType::NONE;

        ButtonStatus::decrease(fromEvent_.getPointingButton());
        FlagStatus::globalFlagStatus().decrease(fromEvent_.getModifierFlag());

        manipulatePureFromModifierFlags(beforeAfterKeys_, Manipulation::DECREASE, true);
        {
          beforeAfterKeys_.call_remap_with_VK_PSEUDO_KEY(EventType::DOWN, remapParams.physicalEventType);

          // We need save FlagStatus at keydown.
          // For example, "Change Space to Shift_L" is enabled,
          //
          // (1) Control_L down
          // (2) Space down
          // (3) Control_L up
          // (4) Space up        -> We should send Control_L+Space here.
          //
          // At (4), Control_L is not presssed.
          // We should send Control_L+Space at (4) because user pressed Space with Control_L at (2).
          //
          // Therefore, we need to save FlagStatus at (2).
          // And restore it at (4).
          //
          flagStatusWhenKeyPressed_ = FlagStatus::globalFlagStatus();

          // Stop modifier flag events until normal key event is happen or physical key down event is happen
          // in order to reduce unnecessary modifier events.
          //
          // For example, we consider the following autogens:
          //
          //    <autogen>
          //      __KeyOverlaidModifier__
          //      KeyCode::COMMAND_L,
          //      KeyCode::CONTROL_L,
          //      KeyCode::ESCAPE,
          //    </autogen>
          //    <autogen>
          //      __KeyOverlaidModifier__
          //      KeyCode::SPACE,
          //      KeyCode::SHIFT_L,
          //      KeyCode::SPACE,
          //    </autogen>
          //
          // * Change the left command key to control key.
          // * Change the space key to shift key.
          // * Send an escape key event when the left command key is pressed alone,
          // * Send a space key event when the space key is pressed alone.
          //
          // When we press keys by this order.
          // #1 Press COMMAND_L.
          // #2 Press SPACE.
          // #3 Release COMMAND_L.
          // #4 Release SPACE.
          //
          // The result is control-space at #4.
          //
          // If we does not stop modifier events, CONTROL_L events are sent at #3 and #4.
          //
          // #1 -> CONTROL_L down.
          // #2 -> SHIFT_L down.
          // #3 -> CONTROL_L up.
          // #4 -> CONTROL_L down, SHIFT_L up, SPACE down, SPACE up, CONTROL_L up.
          //
          // To reduce these events, we ignore modifier events at physical key up.
          //
          // #1 -> CONTROL_L down
          // #2 -> SHIFT_L down.
          // #3 -> Do nothing.
          // #4 -> SHIFT_L up, SPACE down, SPACE up, CONTROL_L up.
          //

          EventOutputQueue::FireModifiers::setIgnorePhysicalUpEvent(true);
        }
        manipulatePureFromModifierFlags(beforeAfterKeys_, Manipulation::INCREASE, true);

        unsigned int ms = periodMS_.get(PeriodMS::Type::SHORT_PERIOD);
        if (ms == 0) {
          fire_timer_callback(nullptr, nullptr);
        } else {
          fire_timer_.setTimeoutMS(ms);
        }

        RemapClassManager::registerPrepareTargetItem(owner_);

      } else {
        // Restore fromEvent_ state to event firing in `dokeyup` for __KeyOverlaidModifier__.
        //
        // For example, we have to restore PointingButton::RIGHT before `dokeyup` for this autogen:
        //
        // <autogen>
        //   __KeyOverlaidModifier__
        //   PointingButton::RIGHT,
        //   KeyCode::VK_MODIFIER_BUTTON2,
        //   PointingButton::RIGHT,
        // </autogen>

        ButtonStatus::increase(fromEvent_.getPointingButton());
        FlagStatus::globalFlagStatus().increase(fromEvent_.getModifierFlag());

        dokeydown(remapParams);
        dokeyup();

        manipulatePureFromModifierFlags(beforeAfterKeys_, Manipulation::DECREASE, true);
        beforeAfterKeys_.call_remap_with_VK_PSEUDO_KEY(EventType::UP, remapParams.physicalEventType);
        manipulatePureFromModifierFlags(beforeAfterKeys_, Manipulation::INCREASE, true);

        RemapClassManager::unregisterPrepareTargetItem(owner_);
      }
      return true;
    }
  }

  return false;
}
    bool
    DependingPressingPeriodKeyToKey::remap(RemapParams& remapParams)
    {
      // Params_KeyboardEventCallBack
      {
        Params_KeyboardEventCallBack* params = remapParams.paramsUnion.get_Params_KeyboardEventCallBack();
        if (params) {
          bool result = keytokey_[KeyToKeyType::FROM].remap(remapParams);
          if (! result) {
            if (params->ex_iskeydown) {
              // another key is pressed.
              dokeydown();
            }
            return false;
          }

          if (params->ex_iskeydown) {
            target_ = this;
            active_ = true;
            periodtype_ = PeriodType::NONE;

            // clear temporary_flags (KeyToKeyType::FROM's flags)
            FlagStatus::set();
            savedflags_ = FlagStatus::makeFlags();

            fire_timer_.setTimeoutMS(periodMS_.get(PeriodMS::Type::SHORT_PERIOD));

          } else {
            dokeydown();
            dokeyup();
          }
          return true;
        }
      }

      // Params_KeyboardSpecialEventCallback
      {
        Params_KeyboardSpecialEventCallback* params = remapParams.paramsUnion.get_Params_KeyboardSpecialEventCallback();
        if (params) {
          // We treat this event as another key has been pressed.
          if (params->ex_iskeydown) {
            dokeydown();
          }
          return false;
        }
      }

      // Params_RelativePointerEventCallback
      {
        Params_RelativePointerEventCallback* params = remapParams.paramsUnion.get_Params_RelativePointerEventCallback();
        if (params) {
          if (params->ex_isbuttondown) {
            dokeydown();
          }
          return false;
        }
      }

      // Params_ScrollWheelEventCallback
      {
        Params_ScrollWheelEventCallback* params = remapParams.paramsUnion.get_Params_ScrollWheelEventCallback();
        if (params) {
          dokeydown();
          return false;
        }
      }

      return false;
    }